We have just upgraded our application from Angular 4 to Angular 5.2.6 The application was built with Angular CLI and CLI recently updated to 1.6.8.
Our application uses lazy loading for some modules. This used to work perfectly with Angular 4, but we are now seeing some strange behaviour.
The application is split into two areas (modules) on of which is 'admin'. The admin module is then also split into modules, one of which is loaded synchronously, the rest lazy.
The issue is with the lazy loaded module: UsersModule.
const routes: Routes = [
{
path: 'admin',
redirectTo: '/admin/requests',
pathMatch: 'full'
},
{
path: 'admin',
component: AdminComponent,
canActivate: [AuthAdminGuard],
children: [
{
path: 'requests',
// syncrhronous because we always hit this route first
loadChildren: () => RequestsModule,
data: { title: 'Requests' }
},
{
path: 'users',
loadChildren: './users/users.module#UsersModule',
data: { title: 'Users' }
},
When the application is built a chunk is created for the users module.
When the user navigates to the 'admin.users' path the application loads the chunk into the head of the page and it is available in the browser source explorer.
BUT the application does not load the module, instead an error is displayed in the console.
Error: Cannot find 'UsersModule' in './users/users.module'
BUT if we remove the module name #UsersModule
I.e. if the module routing is updated from
{
path: 'users',
loadChildren: './users/users.module#UsersModule',
data: { title: 'Users' }
},
to
{
path: 'users',
loadChildren: './users/users.module',
data: { title: 'Users' }
},
The application reloads and now users module is loaded correctly...??
But if we first start with this configuration, no chunk is created for users module...???
NOTE Lazy loaded modules are NOT Imported into parent module.
EDIT Package.json
"dependencies": {
"@agm/core": "^1.0.0-beta.2",
"@angular-devkit/core": "^0.4.2",
"@angular/animations": "^5.2.6",
"@angular/common": "^5.2.6",
"@angular/compiler": "^5.2.6",
"@angular/core": "^5.2.6",
"@angular/forms": "^5.2.6",
"@angular/http": "^5.2.6",
"@angular/platform-browser": "^5.2.6",
"@angular/platform-browser-dynamic": "^5.2.6",
"@angular/platform-server": "^5.2.6",
"@angular/router": "^5.2.6",
"@cloudinary/angular-5.x": "^1.0.1",
"@google-cloud/storage": "^1.3.0",
"@types/google-maps": "^3.2.0",
"@types/googlemaps": "^3.26.14",
"@types/underscore": "^1.8.1",
"angularfire2": "4.0.0-rc.1",
"cloudinary": "^1.9.0",
"cloudinary-core": "^2.3.0",
"core-js": "^2.4.1",
"firebase": "4.1.2",
"material-design-lite": "^1.3.0",
"raven-js": "^3.16.1",
"rxjs": "^5.5.6",
"underscore": "^1.8.3",
"zone.js": "^0.8.4"
},
"devDependencies": {
"@angular/cli": "^1.7.3",
"@angular/compiler-cli": "^5.2.6",
"@types/jasmine": "^2.5.38",
"@types/node": "~6.0.60",
"codelyzer": "^2.0.1",
"cpx": "^1.5.0",
"ejs": "^2.5.6",
"husky": "^0.15.0-rc.8",
"jasmine-core": "~2.5.2",
"jasmine-spec-reporter": "~3.2.0",
"karma": "~1.4.1",
"karma-chrome-launcher": "~2.1.1",
"karma-cli": "~1.0.1",
"karma-coverage-istanbul-reporter": "^0.2.0",
"karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"onchange": "^3.3.0",
"prettier": "1.10.2",
"pretty-quick": "^1.4.1",
"protractor": "~5.1.0",
"ts-node": "~2.0.0",
"tslint": "~4.5.0",
"typescript": "2.4.2"
}