Lazy Loaded Module Inside Another Module Imported w/ .forRoot() Doesn't Load
See original GitHub issuePlease provide us with the following information:
OS?
Windows 7, 8 or 10. Linux (which distribution). Mac OSX (Yosemite? El Capitan?) macOS Sierra
Versions.
Please run
ng --version
. If there’s nothing outputted, please run in a Terminal:node --version
and paste the result here: angular-cli: 1.0.0-beta.26 node: 6.5.0 os: darwin x64 @angular/common: 2.4.5 @angular/compiler: 2.4.5 @angular/core: 2.4.5 @angular/flex-layout: 2.0.0-beta.3 @angular/forms: 2.4.5 @angular/http: 2.4.5 @angular/material: 2.0.0-beta.1 @angular/platform-browser: 2.4.5 @angular/platform-browser-dynamic: 2.4.5 @angular/router: 3.4.5 @angular/compiler-cli: 2.4.5
Repro steps.
Was this an app that wasn’t created using the CLI? What change did you do on your code? etc.
Create a module with routes, including a lazy loaded route
export const exampleRouting = RouterModule.forChild([
{
path : 'examples', component : DefaultLayoutComponent, children : [
{path : '', redirectTo : 'dashboard', pathMatch: 'full'},
{path : 'dashboard', component : DashboardComponent},
{path : 'fake', component : FakeComponent},
{path : 'lazy', loadChildren : './lazy/lazy.module#LazyModule'},
]
}
]);
Have your module need a .forRoot() function
@NgModule({
imports : [
exampleRouting,
...other stuff
],
declarations : [DashboardComponent, FakeComponent],
})
export class ExamplesModule {
static forRoot(): ModuleWithProviders {
return {
ngModule: ExamplesModule,
providers: [MyService]
}
}
}
Import this ExamplesModule into your AppModule like so:
imports: [ExamplesModule.forRoot()]
The log given by the failure.
When trying to navigate to the lazy loaded route, I get the following error:
Unhandled Promise rejection: Cannot find module './lazy/lazy.module'. ; Zone: angular ; Task: Promise.then ; Value:
Issue Analytics
- State:
- Created 7 years ago
- Reactions:3
- Comments:5 (1 by maintainers)
I’m seeing this now since upgrading from beta.21-1 to beta.26. It’s not generating the lazy loaded module bundles anymore.
My route format is as suggested.
{path : 'lazy', loadChildren : 'app/examples/lazy/lazy.module#LazyModule'}
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.