Skip to content

Importing modules that were already loaded by angular-cli.json scripts array throws TypeError #2239

Closed
@thejewdude

Description

@thejewdude

Please provide us with the following information:

  1. OS? Windows 7, 8 or 10. Linux (which distribution). Mac OSX (Yosemite? El Capitan?)
    Windows 7

  2. Versions. Please run ng --version. If there's nothing outputted, please run
    in a Terminal: node --version and paste the result here:
    angular-cli: 1.0.0-beta.14
    node: 6.5.0
    os: win32 x64

  3. Repro steps. Was this an app that wasn't created using the CLI? What change did you
    do on your code? etc.
    ng new moment-test
    cd moment-test
    npm i moment --save
    add moment module to scripts array in angular-cli.json
    add import * as moment from 'moment'; to app.compoment
    call moment()

  4. The log given by the failure. Normally this include a stack trace and some
    more information.
    TypeError: __WEBPACK_IMPORTED_MODULE_1_moment__ is not a function at new AppComponent (http://localhost:4200/main.bundle.js:42865:22) at DebugAppView._View_AppComponent_Host0.createInternal (AppComponent_Host.ngfactory.js:16:28) at DebugAppView.AppView.create (http://localhost:4200/main.bundle.js:53694:21) at DebugAppView.create (http://localhost:4200/main.bundle.js:53906:44) at ComponentFactory.create (http://localhost:4200/main.bundle.js:37649:36) at ApplicationRef_.bootstrap (http://localhost:4200/main.bundle.js:24070:40) at http://localhost:4200/main.bundle.js:23979:89 at Array.forEach (native) at PlatformRef_._moduleDoBootstrap (http://localhost:4200/main.bundle.js:23979:42) at http://localhost:4200/main.bundle.js:23947:27 at ZoneDelegate.invoke (http://localhost:4200/main.bundle.js:64689:28) at Object.onInvoke (http://localhost:4200/main.bundle.js:54490:37) at ZoneDelegate.invoke (http://localhost:4200/main.bundle.js:64688:34) at Zone.run (http://localhost:4200/main.bundle.js:64582:43) at http://localhost:4200/main.bundle.js:64948:57 at ZoneDelegate.invokeTask (http://localhost:4200/main.bundle.js:64722:37) at Object.onInvokeTask (http://localhost:4200/main.bundle.js:54481:37) at ZoneDelegate.invokeTask (http://localhost:4200/main.bundle.js:64721:42) at Zone.runTask (http://localhost:4200/main.bundle.js:64622:47) at drainMicroTaskQueue (http://localhost:4200/main.bundle.js:64854:35)ErrorHandler.handleError @ error_handler.js:51(anonymous function) @ application_ref.js:209ZoneDelegate.invoke @ zone.js:203onInvoke @ ng_zone_impl.js:43ZoneDelegate.invoke @ zone.js:202Zone.run @ zone.js:96(anonymous function) @ zone.js:462ZoneDelegate.invokeTask @ zone.js:236onInvokeTask @ ng_zone_impl.js:34ZoneDelegate.invokeTask @ zone.js:235Zone.runTask @ zone.js:136drainMicroTaskQueue @ zone.js:368 error_handler.js:54ERROR CONTEXT:ErrorHandler.handleError @ error_handler.js:54(anonymous function) @ application_ref.js:209ZoneDelegate.invoke @ zone.js:203onInvoke @ ng_zone_impl.js:43ZoneDelegate.invoke @ zone.js:202Zone.run @ zone.js:96(anonymous function) @ zone.js:462ZoneDelegate.invokeTask @ zone.js:236onInvokeTask @ ng_zone_impl.js:34ZoneDelegate.invokeTask @ zone.js:235Zone.runTask @ zone.js:136drainMicroTaskQueue @ zone.js:368 error_handler.js:55DebugContext {_view: _View_AppComponent_Host0, _nodeIndex: 0, _tplRow: 0, _tplCol: 0}ErrorHandler.handleError @ error_handler.js:55(anonymous function) @ application_ref.js:209ZoneDelegate.invoke @ zone.js:203onInvoke @ ng_zone_impl.js:43ZoneDelegate.invoke @ zone.js:202Zone.run @ zone.js:96(anonymous function) @ zone.js:462ZoneDelegate.invokeTask @ zone.js:236onInvokeTask @ ng_zone_impl.js:34ZoneDelegate.invokeTask @ zone.js:235Zone.runTask @ zone.js:136drainMicroTaskQueue @ zone.js:368 zone.js:355Unhandled Promise rejection: Error in ./AppComponent class AppComponent_Host - inline template:0:0 caused by: __WEBPACK_IMPORTED_MODULE_1_moment__ is not a function ; Zone: <root> ; Task: Promise.then ; Value: ViewWrappedError {_nativeError: Error: Error in ./AppComponent class AppComponent_Host - inline template:0:0 caused by: __WEBPACK_IM…, originalError: TypeError: __WEBPACK_IMPORTED_MODULE_1_moment__ is not a function at new AppComponent (http://lo…, context: DebugContext} TypeError: __WEBPACK_IMPORTED_MODULE_1_moment__ is not a function at new AppComponent (http://localhost:4200/main.bundle.js:42865:22) at DebugAppView._View_AppComponent_Host0.createInternal (AppComponent_Host.ngfactory.js:16:28) at DebugAppView.AppView.create (http://localhost:4200/main.bundle.js:53694:21) at DebugAppView.create (http://localhost:4200/main.bundle.js:53906:44) at ComponentFactory.create (http://localhost:4200/main.bundle.js:37649:36) at ApplicationRef_.bootstrap (http://localhost:4200/main.bundle.js:24070:40) at http://localhost:4200/main.bundle.js:23979:89 at Array.forEach (native) at PlatformRef_._moduleDoBootstrap (http://localhost:4200/main.bundle.js:23979:42) at http://localhost:4200/main.bundle.js:23947:27 at ZoneDelegate.invoke (http://localhost:4200/main.bundle.js:64689:28) at Object.onInvoke (http://localhost:4200/main.bundle.js:54490:37) at ZoneDelegate.invoke (http://localhost:4200/main.bundle.js:64688:34) at Zone.run (http://localhost:4200/main.bundle.js:64582:43) at http://localhost:4200/main.bundle.js:64948:57 at ZoneDelegate.invokeTask (http://localhost:4200/main.bundle.js:64722:37) at Object.onInvokeTask (http://localhost:4200/main.bundle.js:54481:37) at ZoneDelegate.invokeTask (http://localhost:4200/main.bundle.js:64721:42) at Zone.runTask (http://localhost:4200/main.bundle.js:64622:47) at drainMicroTaskQueue (http://localhost:4200/main.bundle.js:64854:35)

  5. Mention any other details that might be useful.
    I'm not sure that this a bug.
    I currently use primeng's schedule component which has a dependency on momentjs. This requires loading momentjs before importing the ScheduleModule in my app.module. I would like to use momentjs throughout my application but when I import it into any class I get a TypeError. This issue is not unique to momentjs: any library added to the angular-cli.json scripts array shows the same behavior.


Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions