angular-cli: Does not generate lazy routes chunks
OS?
Mac OS Sierra
Versions.
@angular/cli: 1.0.0-rc.1
node: 7.4.0
os: darwin x64
@angular/common: 4.0.0-rc.2
@angular/compiler: 4.0.0-rc.2
@angular/core: 4.0.0-rc.2
@angular/forms: 4.0.0-rc.2
@angular/http: 4.0.0-rc.2
@angular/platform-browser: 4.0.0-rc.2
@angular/platform-browser-dynamic: 4.0.0-rc.2
@angular/router: 4.0.0-rc.2
Repro steps.
At first, I use ng build --prod --watch=true
with correct path for lazy module, but I can’t see any lazy route chunks
const appRoutes: Routes = [
{
path: 'admin', component: LayoutComponent, canActivate: [AuthGuardService],
children: [
{path: 'bike', loadChildren: 'app/bike/bike.module#BikeModule',},
]},
];
Hash: f9d9290bb80836ad5ad2
Time: 24703ms
chunk {0} polyfills.062e66d5506f88fa9a04.bundle.js (polyfills) 200 kB {4} [initial] [rendered]
chunk {1} main.1b88c492928b4fd2fc9d.bundle.js (main) 120 kB {3} [initial] [rendered]
chunk {2} styles.9f6e9dbf53f7c0872d3c.bundle.css (styles) 175 bytes {4} [initial] [rendered]
chunk {3} vendor.ef6a6d2029727798afd2.bundle.js (vendor) 2.02 MB [initial] [rendered]
chunk {4} inline.0605372a06e6490f08a6.bundle.js (inline) 0 bytes [entry] [rendered]
then I use an error path like this: ./app/bike/bike.module#BikeModule
finally I change back: app/bike/bike.module#BikeModule
I see the lazy route chunk output:
Hash: c192e290b753f07c3589
Time: 11943ms
chunk {0} polyfills.062e66d5506f88fa9a04.bundle.js (polyfills) 200 kB {4} [initial]
chunk {1} main.15453f3e2945e4eade17.bundle.js (main) 120 kB {3} [initial] [rendered]
chunk {2} styles.9f6e9dbf53f7c0872d3c.bundle.css (styles) 175 bytes {4} [initial]
chunk {3} vendor.be4ca73bd2f535511b0a.bundle.js (vendor) 2.02 MB [initial] [rendered]
chunk {4} inline.206e421169df75a8322e.bundle.js (inline) 0 bytes [entry] [rendered]
chunk {5} 5.00405610a134f55380e0.chunk.js 11.4 kB {1} [rendered]
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 11
- Comments: 34 (7 by maintainers)
I’m still seeing this problem. I’ve actually edited the route module, and that fixes it, but I need to deploy with the lazy loaded module chunks! I’ve updated the latest the angular-compiler, and I’m using angular 4. Does anyone have a workaround besides editing the app-route-module???
I’m still not sure where stuff is breaking exactly, but it seems to be related to having the routes in
AppRoutingModule
.Having them in
app.module.ts
instead works to work fine:FYI, this same thing is happening with @ngtools in webpack if you use a vendor file and webpack.DllPlugin. The bundles aren’t created but it expects them to be there.
Using awesome-typescript makes it work again but then you lose AOT obviously.
@filipesilva I find out that it’s a bug for @angular/compiler-cli, I have commit a pull request to fix it. angular/angular#16438
I tried an app with some lazy loaded routes and could see the lazy chunks being correctly generated on
ng serve
andng build --watch
. Can you upload a repo where you see this behaviour?I have the same problem as described by gmetrix commented on 28 Sep 2017. with CLI 1.6.6 and NG 5.2.2.
Strange enough, the example code from the tutorial at https://angular.io/guide/lazy-loading-ngmodules is working fine. Ng build generates module chunk js properly. though my app structure is pretty similar to the example in the tutorial.
I still have this issue. Upgraded the cli to 1.5. I have one lazy loaded route right now. The chunk file is created, however the I get an error because it’s not adding the output directory to the path for the script tag. Anyone else having this?
I am running into the same issue. I am using @angular/cli 1.0.1 and @angular 4.0.1. Is there a workaround or the lazy loading is not working for the latest @angular/cli?
Actually, the core of it seems to actually be the
forRoot
method. Changing the import fromAppRoutingModule.forRoot(),
to justAppRoutingModule
makes it work.@hansl I remember there was some conversation about
forRoot
, is this behaviour intended?Thank you for making this repro.
I cloned it, ran
npm install
, ranng serve
and could see no lazy routes being generated. Then I added a newline insrc/app/app-routing.module.ts
and saved, and actually saw this error:I tried using linking master copy of the CLI, and on rebuild I didn’t see an error and instead I saw a single extra lazy chunk called
5.chunk.js
. Which is also pretty weird… it should be0.chunk.js
instead.There’s something odd here, will investigate further.
This also happens to me even on
ng serve
. when i add the--aot
flag it generates the chunks.OS
macOS Sierra 10.12.3
Versions.
@angular/cli: 1.0.0-rc.1 node: 6.10.0 @angular/common: 2.4.9 @angular/compiler: 2.4.9 @angular/core: 2.4.9 @angular/forms: 2.4.9 @angular/http: 2.4.9 @angular/platform-browser: 2.4.9 @angular/platform-browser-dynamic: 2.4.9 @angular/router: 3.4.9