Skip to content

bug: lazy loading routes with property undefined and error when redirecting #3662

Closed
@jackrobertscott

Description

@jackrobertscott

Please provide us with the following information:

OS?

Mac OSX El Capitan

Versions.

angular-cli: 1.0.0-beta.22-1
node: 6.9.1
os: darwin x64

Repro steps.

Yes, this app was created with the CLI. The app runs fine on my laptop. However, on my larger, more powerful Mac Desktop, the error(s) occur. 2 errors occur which are both associated with my lazy loading of modules.

  1. It is trying to call the property of listLazyRoutes on an undefined variable.
  2. It won't let me set a redirect url to a lazy loaded module.

The log given by the failure.

The listLazyRoutes error:

webpack: bundle is now INVALID.
Hash: d5cf9613b92421a92d2d
Time: 1688ms
chunk    {0} main.bundle.js, main.bundle.map (main) 10.9 kB {2} [initial]
chunk    {1} styles.bundle.js, styles.bundle.map (styles) 10.6 kB {3} [initial]
chunk    {2} vendor.bundle.js, vendor.bundle.map (vendor) 3.33 MB [initial]
chunk    {3} inline.bundle.js, inline.bundle.map (inline) 0 bytes [entry]

ERROR in Cannot read property 'listLazyRoutes' of undefined
webpack: bundle is now VALID.

The error that prevents me from setting a redirect url to a lazy loaded path like the following (and yes, I have tried relative urls).

const routes: Routes = [
  { path: '', redirectTo: 'auth/login', pathMatch: 'full' },
  { path: 'auth', loadChildren: 'app/auth/auth.module#AuthModule' },
];

Error log:

Error: Uncaught (in promise): Error: Cannot find module 'app/auth/auth.module'.
Error: Cannot find module 'app/auth/auth.module'.
    at webpackEmptyContext (src async:2)
    at SystemJsNgModuleLoader.loadAndCompile (system_js_ng_module_factory_loader.js:46)
    at SystemJsNgModuleLoader.load (system_js_ng_module_factory_loader.js:38)
    at RouterConfigLoader.loadModuleFactory (router_config_loader.js:42)
    at RouterConfigLoader.load (router_config_loader.js:33)
    at MergeMapSubscriber.project (apply_redirects.js:242)
    at MergeMapSubscriber._tryNext (mergeMap.js:110)
    at MergeMapSubscriber._next (mergeMap.js:100)
    at MergeMapSubscriber.Subscriber.next (Subscriber.js:89)
    at ScalarObservable._subscribe (ScalarObservable.js:49)
    at webpackEmptyContext (src async:2)
    at SystemJsNgModuleLoader.loadAndCompile (system_js_ng_module_factory_loader.js:46)
    at SystemJsNgModuleLoader.load (system_js_ng_module_factory_loader.js:38)
    at RouterConfigLoader.loadModuleFactory (router_config_loader.js:42)
    at RouterConfigLoader.load (router_config_loader.js:33)
    at MergeMapSubscriber.project (apply_redirects.js:242)
    at MergeMapSubscriber._tryNext (mergeMap.js:110)
    at MergeMapSubscriber._next (mergeMap.js:100)
    at MergeMapSubscriber.Subscriber.next (Subscriber.js:89)
    at ScalarObservable._subscribe (ScalarObservable.js:49)
    at resolvePromise (zone.js:468)
    at resolvePromise (zone.js:453)
    at zone.js:502
    at ZoneDelegate.invokeTask (zone.js:265)
    at Object.onInvokeTask (ng_zone.js:227)
    at ZoneDelegate.invokeTask (zone.js:264)
    at Zone.runTask (zone.js:154)
    at drainMicroTaskQueue (zone.js:401)

Mention any other details that might be useful.

I believe the listLazyRoutes property is in the node_modules/@ngtools/webpack/src/plugin.js file:

// Process the lazy routes
_this._lazyRoutes = {};
var allLazyRoutes = compiler_cli_1.__NGTOOLS_PRIVATE_API_2.listLazyRoutes({
  program: _this._program,
  host: _this._compilerHost,
  angularCompilerOptions: _this._angularCompilerOptions,
  entryModule: _this._entryModule
});

Like I said, this issue doesn't occur on my laptop. Maybe it has to do with the speed at which the modules are loaded, running code that accesses the property of an object that hasn't yet been set? I'm not sure...

Thanks everyone!

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