question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Lazy Loaded Module Inside Another Module Imported w/ .forRoot() Doesn't Load

See original GitHub issue

Please 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:closed
  • Created 7 years ago
  • Reactions:3
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
andyruecommented, Jan 30, 2017

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'}

0reactions
angular-automatic-lock-bot[bot]commented, Sep 6, 2019

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Lazy-loading feature modules - Angular
forRoot(routes) to the AppRoutingModule imports array. This lets Angular know that the AppRoutingModule is a routing module and forRoot() specifies that this is ......
Read more >
angular - All except one module doesn't load in lazy loading
I wrote the below code for lazyloading. All the modules except EmployerModule load well when I go to their corresponding routes.
Read more >
Working With Lazy Loading Modules and Preload Routing ...
Import every module in the app.module and register in the imports section. We need to configure the Router module to navigate to every...
Read more >
How to Nest Lazy-Loaded Modules - DEV Community ‍ ‍
Use forRoot() in the root module which is usually app.module.ts or the corresponding routing module. The module, its components, and all of its ......
Read more >
How to use MDB in child modules? including lazy loading
Now, in Users module I need to import your MDB module to be able to use components. Think of it as those modules...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found