I
I
iliyaisd2018-09-13 05:22:14
Angular
iliyaisd, 2018-09-13 05:22:14

After upgrading Angular from 4 to 6, how do I get lazy routes to work?

There are lazy routes in a project written under Angular 4.
After upgrading to 6, a lot of errors are generated:

ERROR in ./src/$$_lazy_route_resource lazy namespace object
Module not found: Error: Can't resolve '/path/to/project/src/app/lazy/about/about.module.ngfactory.js' in '/path/to/project/src/$$_lazy_route_resource'

And there are many of them, for each route.
Connect like this:
export const AppRoutes: Routes = [
(...) 
  {
    path: 'about-us',
    loadChildren: './lazy/about/about.module#AboutModule'
  },
(...) 
]

import {RouterModule} from '@angular/router';
import {ModuleWithProviders} from '@angular/core';

import {AppRoutes} from './app.routes';
/**
 * @type {ModuleWithProviders}
 */
export const AppRoutingModule: ModuleWithProviders = RouterModule.forRoot(AppRoutes);

And then in app.module.ts AppRoutingModule is added to imports.
I compile as:
ng build --prod --aot --output-hashing=all
As you can see from the error, it tries to look for *.ngfactory.js, which does not exist.
This did not help: https://github.com/angular/angular-cli/issues/11835
How can I fix it?
Thank you very much in advance!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question