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

Does not generate lazy routes chunks

Open Adol1111 opened this issue 9 years ago • 34 comments

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]

Adol1111 avatar Mar 03 '17 15:03 Adol1111

The reason why this happens is because you have Angular components in your vendor file. They must be included in your main angular chunk. As soon as you don't, it won't generate the chunks properly. So you need to have code that moves them into the main package and not in the vendor.js if production and using ngtools.

JohnGalt1717 avatar Nov 03 '17 19:11 JohnGalt1717

using angularcli @JohnGalt1717 not to sure on that. have example maybe.

uvconnects avatar Nov 03 '17 19:11 uvconnects

I use Webpack but the same principle will apply. IF you have a vendor.js being generated make sure that when choosing production you don't have any angular libraries in vendor.js otherwise this will happen.

JohnGalt1717 avatar Nov 03 '17 19:11 JohnGalt1717

ok @JohnGalt1717 so weird I built again and then everything fell in place. Not sure. but it works now and made individual chucks.

uvconnects avatar Nov 03 '17 21:11 uvconnects

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?

TerrySlack avatar Nov 06 '17 22:11 TerrySlack

I have also upgraded the cli to 1.5 and still facing same issue. If without changing anything, I just save child module (it will re-compile app) than that child routes will work fine. Does anybody have any solution?

pateldol avatar Nov 14 '17 13:11 pateldol

@pateldol Can you upload a repo? In my case, it's a bug about compiler-cli which version under 4.1.3, not cli.

Adol1111 avatar Nov 15 '17 13:11 Adol1111

for some reason it just started working. after I compliled 8 times. weird.

uvconnects avatar Nov 15 '17 16:11 uvconnects

Any news?

ghost avatar Nov 19 '17 22:11 ghost

Yes. I deleted all node modules and then made sure I had at least 2.4 typescript installed. and it worked.

Sent with MailTag http://www.mailtag.io

On Sun, Nov 19, 2017 at 5:53 PM, EnricoMazzucchelli < [email protected]> wrote:

Any news?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/angular/angular-cli/issues/5204#issuecomment-345557140, or mute the thread https://github.com/notifications/unsubscribe-auth/ADu4owVaeJpfQcL9bEF3TLrefjJQ7kxSks5s4LF8gaJpZM4MSaVQ .

--

Anthony P (919) 671-7234

uvconnects avatar Nov 20 '17 00:11 uvconnects

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.

zijianhuang avatar Jan 31 '18 04:01 zijianhuang

Can I load specific lazy loaded chunk in prod build ?

mistrykaran91 avatar Jul 23 '18 11:07 mistrykaran91

I met the same issue, in angular5.0 + webpack3.10.0 no chunk files for lazy loading. here is my root cause, hope can help someone: in my app-routing.module.ts:

import { NgModule } from '@angular/core';
//import { PreloadAllModules, RouterModule, Routes } from '@angular/router';
import { RouterModule, Routes } from '@angular/router';
import { AppCustomPreloader } from './app.custom.preloader';

const routes: Routes = [
    {
        path: 'dashboard',
        loadChildren: './modules/dashboard/dashboard.module#DashboardModule',
        data: { preload: true }
    },
    { path: 'settings', loadChildren: './modules/settings/settings.module#SettingsModule' },
    { path: 'reports', loadChildren: './modules/reports/reports.module#ReportsModule' },

];

@NgModule({
    // imports: [RouterModule.forRoot(routes, { preloadingStrategy: PreloadAllModules, useHash: true })],
    imports: [RouterModule.forRoot(routes, { preloadingStrategy: AppCustomPreloader, useHash: true })],
    exports: [RouterModule],
    providers: [AppCustomPreloader]
})
export class AppRoutingModule { }

and at the same time I import DashboardModule SettingsModule SettingsModule in my app.module.ts

that's the reason why no chunk file for lazy loading module, I guess if there has loadchildren for business modlue and import it in app.module.ts, then angular just ignore the lazy loading settings.

remove imported module in app.module.ts , it's working fine.

LiMeii avatar Oct 08 '18 03:10 LiMeii

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.