angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

Lazy loaded chunk not generated when lazy route is a child of non-lazy route.

Open jdcrecur opened this issue 8 years ago • 100 comments

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

jdcrecur avatar Feb 02 '18 14:02 jdcrecur

I have the same issue +1

ZeevKatz avatar Feb 04 '18 15:02 ZeevKatz

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 avatar Feb 27 '18 13:02 denyo

@denyo Confirmed bug on cli 1.7.0 and 1.7.1. Downgrading to 1.6.8 works fine.

supergithubo avatar Feb 28 '18 18:02 supergithubo

@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.

denyo avatar Mar 01 '18 11:03 denyo

+1

FirassKoubaa avatar Mar 01 '18 16:03 FirassKoubaa

+1

chrisbbe avatar Mar 01 '18 21:03 chrisbbe

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:

  1. Remove lazy loaded module from any barrel files.
  2. Do not import lazy loaded module, using es6 import statement.
  3. Restart angular-cli app.

For some reason, I had to kill node process and restart the app before angular-cli would work.

RyanLynnWood avatar Mar 02 '18 22:03 RyanLynnWood

@RyanLynnWood that did not sole the issue for me , still struggling

FirassKoubaa avatar Mar 04 '18 13:03 FirassKoubaa

@RyanLynnWood is it still fixed from a cold start, and the build folder removed?

jdcrecur avatar Mar 04 '18 19:03 jdcrecur

+1 still an issue with 1.7.2

sennl avatar Mar 06 '18 16:03 sennl

Confirmed as still an issue in 1.7.2

devakone avatar Mar 07 '18 14:03 devakone

Bug persists with 1.7.3.

denyo avatar Mar 08 '18 06:03 denyo

Confirmed bug on cli 1.7.2. Downgrading to 1.6.8 works fine.

charlesartbr avatar Mar 11 '18 00:03 charlesartbr

Confirmed bug on CLI 1.7.3. with Angular 5.2.8 Downgrading to 1.6.8 works fine.

webcat12345 avatar Mar 13 '18 15:03 webcat12345

Confirmed bug on CLI 1.7.3. with Angular 5.2.8 Downgrading to 1.6.8 works fine.

MALIK-0 avatar Mar 13 '18 21:03 MALIK-0

restart ng server && work fine #

changan712 avatar Mar 14 '18 05:03 changan712

The only workaround for me is to change "loadChildren" string while --watch process running. (CLI 1.6.8, Core and Router 5.2.8)

i23591326 avatar Mar 14 '18 15:03 i23591326

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 () at webpackAsyncContext (eval at ./src/$$_lazy_route_resource lazy recursive (main.bundle.js:13), :14:34) at SystemJsNgModuleLoader.loadAndCompile (core.js:6558) at SystemJsNgModuleLoader.load (core.js:6542) at RouterConfigLoader.loadModuleFactory (router.js:4584) at RouterConfigLoader.load (router.js:4564) at eval (router.js:6981) at PreloadAllModules.preload (router.js:6857) at RouterPreloader.preloadConfig (router.js:6980) at RouterPreloader.processRoutes (router.js:6959) at Array.map () at webpackAsyncContext (eval at ./src/$$_lazy_route_resource lazy recursive (main.bundle.js:13), :14:34) at SystemJsNgModuleLoader.loadAndCompile (core.js:6558) at SystemJsNgModuleLoader.load (core.js:6542) at RouterConfigLoader.loadModuleFactory (router.js:4584) at RouterConfigLoader.load (router.js:4564) at eval (router.js:6981) at PreloadAllModules.preload (router.js:6857) at RouterPreloader.preloadConfig (router.js:6980) at RouterPreloader.processRoutes (router.js:6959) at resolvePromise (zone.js:809) at eval (zone.js:861) at ZoneDelegate.invokeTask (zone.js:421) at Object.onInvokeTask (core.js:4740) at ZoneDelegate.invokeTask (zone.js:420) at Zone.runTask (zone.js:188) at drainMicroTaskQueue (zone.js:595)

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

PrashanthGowda avatar Mar 15 '18 12:03 PrashanthGowda

+1 Same problem here using Angular CLI 1.7.2.

I'm using ng serve --aot as a workaround

fromage9747 avatar Mar 16 '18 10:03 fromage9747

+1 same problem here using Angular Cli 1.7.3

Console: TypeError: undefined is not a function at Array.map () at webpackAsyncContext (eval at ./src/$$_lazy_route_resource lazy recursive (main.bundle.js:13), :10:34) at SystemJsNgModuleLoader.loadAndCompile (core.js:6558) at SystemJsNgModuleLoader.load (core.js:6542) at RouterConfigLoader.loadModuleFactory (router.js:4584) at RouterConfigLoader.load (router.js:4564) at MergeMapSubscriber.eval [as project] (router.js:2056) at MergeMapSubscriber._tryNext (mergeMap.js:128) at MergeMapSubscriber._next (mergeMap.js:118) at MergeMapSubscriber.Subscriber.next (Subscriber.js:92) at Array.map () at webpackAsyncContext (eval at ./src/$$_lazy_route_resource lazy recursive (main.bundle.js:13), :10:34) at SystemJsNgModuleLoader.loadAndCompile (core.js:6558) at SystemJsNgModuleLoader.load (core.js:6542) at RouterConfigLoader.loadModuleFactory (router.js:4584) at RouterConfigLoader.load (router.js:4564) at MergeMapSubscriber.eval [as project] (router.js:2056) at MergeMapSubscriber._tryNext (mergeMap.js:128) at MergeMapSubscriber._next (mergeMap.js:118) at MergeMapSubscriber.Subscriber.next (Subscriber.js:92) at resolvePromise (zone.js:809) at resolvePromise (zone.js:775) at eval (zone.js:858) at ZoneDelegate.invokeTask (zone.js:421) at Object.onInvokeTask (core.js:4740) at ZoneDelegate.invokeTask (zone.js:420) at Zone.runTask (zone.js:188) at drainMicroTaskQueue (zone.js:595) at

ashutoshagg avatar Mar 18 '18 09:03 ashutoshagg