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

Angular 7 : lazy loading compilation does not generate chunks without a force load.

Open kunal00731 opened this issue 6 years ago • 2 comments

In my application , lazy loading was perfectly working in Angular 4 . However , after I migrated to Angular 7 , the lazy loading and routing has stopped working when I use ng serve.

The routes for the application are defined in app.module.ts like this :

		    RouterModule.forRoot([
			  { path: 'info/:gitCode/:pemCode/:getRtComponent', component: RedComponent },
			  { path: 'info/:gitCode/:pemCode/:getFaq/:getRtComponent', component: RedComponent },
			  { path: 'loadGuardsInfo/:gitCode/:pemCode/:getRtComponent', component: RedComponent },
			  { path: 'loadGuardsInfo/:getRtComponent', component: RedComponent },
			  { path: 'recDet', component: RecDetComponent },
			  { path: 'SlaveComponent/:pfScreen', loadChildren: './ally/slave/slave.module#SlaveModule' },
			  { path: 'MasterComponent/:pfScreen', loadChildren: './ally/master/master.module#MasterModule' },
			  { path: 'DashedComponent/:pfScreen', loadChildren: './ally/dashed/dashed.module#DashedModule' }
			  ])
		  ],
		  providers: [ReqService, { provide: APP_BASE_HREF, useValue: './' }, {
			provide: ErrorHandler,
			useClass: GlobalErrorHandler
		  }, { provide: LocationStrategy, useClass: HashLocationStrategy }],
		  bootstrap: [AppComponent],
		  exports: []

I have gone through a lot of articles on the internet about this and tried out a lot of things , but none worked .

When I first try ng serve, I just get 6 chunks : main.js, polyfills.js, runtime.js, scripts.js, styles.js and vendor.js along with various typescript errors (I am okay with typescript errors since they are coming up as typescript has been updated from 2.4 to 3.1 and according to me they are expected and can be resolved) . What's strange is : when I now go to the app.module.ts, where my routes are mentioned and just try : CONTROL+S by introducing some blank characters using backspace , then all the lazy loading named chunks start showing up in the terminal . This issue is very similar to the issue that was reported by @ceyhunn here : https://github.com/angular/angular/issues/27023#issuecomment-491206139

Also , every lazy loaded module , has a routing established in it like(e.g. for SlaveModule) :

 RouterModule.forChild([
  {path:'', component:SlaveComponent}
 ])

Before the upgrade : enter image description here

After the upgrade : enter image description here

Can the angular experts here tell me as to what's going wrong and how can I solve these issues ?

I have raised the question in stackoverflow as well, but got no answer : https://stackoverflow.com/questions/64440466/angular-7-why-does-lazy-loading-compilation-does-not-generate-chunks

kunal00731 avatar Oct 21 '20 04:10 kunal00731

Hi @klauskpm,

Angular 7 is no longer under support by the Angular team. The current LTS version is 8 which will end on the 28th November 2020. See https://angular.io/guide/releases#support-policy-and-schedule for more info. Kindly update to a more recent version of Angular.

If the problem persists in your application after upgrading, please open a new issue, provide a minimal repository reproducing the problem. You can read here why this is needed. A good way to make a minimal repro is to create a new app via ng new repro-app and adding the minimum possible code to show the problem. Then you can push this repository to github and link it here.

This might be related to your directory structure so its really important to get an accurate repro to diagnose this.

alan-agius4 avatar Oct 21 '20 07:10 alan-agius4

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.