Lazy loaded chunk not generated when lazy route is a child of non-lazy route.
Versions
Angular CLI: 1.6.6
Node: 8.9.4
OS: linux x64
Angular: 5.2.2
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router, service-worker
@angular/cdk: 5.1.0
@angular/cli: 1.6.6
@angular/material: 5.1.0
@angular-devkit/build-optimizer: 0.0.42
@angular-devkit/core: 0.0.29
@angular-devkit/schematics: 0.0.52
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 1.9.6
@schematics/angular: 0.1.17
typescript: 2.4.2
webpack-bundle-analyzer: 2.9.2
webpack: 3.10.0
Repro steps
- Create an angular 5 app
- In the main root module load 2 routes by module, but not lazy loaded.
- In one of the child modules, lazy load subsequent modules
Observed behavior
Error thrown when loading the lazy route. When search for the chunk expected in the filesystem it is not there.
Desired behavior
The lazy loaded route is loaded via a chunk create created by webpack
Mention any other details that might be useful (optional)
SO question raised, but nobody has an answer: https://stackoverflow.com/questions/48523411/angular-5-with-angular-cli-non-lazy-loading-modules-in-the-router
Demo code of the exact issue on github: https://github.com/jdcrecur/ang5ModuleRouting
I have the same issue +1
I just noticed the same issue when upgrading to angular 5.2.6 and angular/cli 1.7.1. My lazy route is defined like
const appRoutes: Routes = [
{
path: 'whatever',
loadChildren: 'app/modules/whatever/whatever.module#WhatEverModule',
canActivate: [AuthGuard],
}
]
And then imported within RoutingModule like RouterModule.forRoot(appRoutes).
RoutingModule is then imported in AppModule.
Until the upgrade everything was working perfectly.
Since the update the app compiles with ng serve but when I access the lazy route I get this error
core.js:1448 ERROR Error: Uncaught (in promise): TypeError: undefined is not a function
TypeError: undefined is not a function
at Array.map (<anonymous>)
at webpackAsyncContext (eval at ./src/$$_lazy_route_resource lazy recursive (main.bundle.js:20), <anonymous>:10:34)
at SystemJsNgModuleLoader.loadAndCompile (core.js:6558)
at SystemJsNgModuleLoader.load (core.js:6542)
at RouterConfigLoader.loadModuleFactory (router.js:4543)
at RouterConfigLoader.load (router.js:4523)
...
However it still works with ng serve --aot.
So it seems to be a JIT problem.
ng -v just for a reference
Angular CLI: 1.7.1
Node: 7.10.0
OS: darwin x64
Angular: 5.2.6
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router
@angular/cli: 1.7.1
@angular-devkit/build-optimizer: 0.3.2
@angular-devkit/core: 0.3.2
@angular-devkit/schematics: 0.3.2
@ngtools/json-schema: 1.2.0
@ngtools/webpack: 1.10.1
@schematics/angular: 0.3.2
@schematics/package-update: 0.3.2
typescript: 2.6.2
webpack: 3.11.0
There is also this recent issue on stack overflow: https://stackoverflow.com/questions/48991372/angular-error-uncaught-in-promise-at-webpackasynccontext-eval-at-src
@denyo
Confirmed bug on cli 1.7.0 and 1.7.1.
Downgrading to 1.6.8 works fine.
@supergithubo thanks!
angular cli at 1.6.8 does the trick in deed.
I also tried the most recent 1.7.2. cli but the bug is still there.
+1
+1
Finally solved. Im running angular/cli ~1.7.0
the cause for me was due to the fact that in app.module, I was importing a file from a barrel that was also exporting the module i was trying to lazy load.
In all, make sure all the following are done:
- Remove lazy loaded module from any barrel files.
- Do not import lazy loaded module, using es6 import statement.
- Restart angular-cli app.
For some reason, I had to kill node process and restart the app before angular-cli would work.
@RyanLynnWood that did not sole the issue for me , still struggling
@RyanLynnWood is it still fixed from a cold start, and the build folder removed?
+1 still an issue with 1.7.2
Confirmed as still an issue in 1.7.2
Bug persists with 1.7.3.
Confirmed bug on cli 1.7.2. Downgrading to 1.6.8 works fine.
Confirmed bug on CLI 1.7.3. with Angular 5.2.8 Downgrading to 1.6.8 works fine.
Confirmed bug on CLI 1.7.3. with Angular 5.2.8 Downgrading to 1.6.8 works fine.
restart ng server && work fine #
The only workaround for me is to change "loadChildren" string while --watch process running. (CLI 1.6.8, Core and Router 5.2.8)
Angular Version: 5.2.8 Cli Version 1.7.3
Error on Lazy loading,
Console:
ERROR Error: Uncaught (in promise): TypeError: undefined is not a function
TypeError: undefined is not a function
at Array.map (
Update I was using typescript 2.7.2, i was getting some warning for using typescript 2.7.2 so i downgraded my typescript to version 2.6.2 that error is not showing up, lazy loading is working fine
+1 Same problem here using Angular CLI 1.7.2.
I'm using ng serve --aot as a workaround
+1 same problem here using Angular Cli 1.7.3
Console:
TypeError: undefined is not a function
at Array.map (