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.

NX(v8): Lazy loading from LIB directory causes "module not found .. index.ngfactory" on prod build

See original GitHub issue
  • I am running the latest version
  • I checked the documentation and found no answer
  • I checked to make sure that this issue has not already been filed
  • I’m reporting the issue to the correct repository (not related to Angular, AngularCLI or any dependency)

Expected Behavior

To be able to load lazy modules in prod, it currently fails on a production build

Current Behavior

Using both ng server and ng build, all seems to go well. But doing an ng build --prod and any libraries that are in the libs folder causes the following error

Date: 2019-06-07T14:00:34.648Z
Hash: 7f5200abcc9a74395181
Time: 11800ms
chunk {0} runtime.5ba2ece7ab2ffcd4c683.js (runtime) 2.16 kB [entry] [rendered]
chunk {1} main.f737b50ade1e2927999b.js (main) 284 kB [initial] [rendered]
chunk {2} polyfills.079fa0a87867aebb25de.js (polyfills) 42.9 kB [initial] [rendered]
chunk {3} polyfills-es5.713635137766a4d7e797.js (polyfills-es5) 68 kB [initial] [rendered]
chunk {4} styles.09e2c710755c8867a460.css (styles) 0 bytes [initial] [rendered]
chunk {5} 5.3db1d83002b02c75fae1.js () 436 bytes  [rendered]

ERROR in ./src/app/app.module.ts
Module not found: Error: Can't resolve './../../../../libs/my-test/index.ngfactory' in '/Users/ian/Development/Personal/typescript/test/apps/test-ui/src/app'

I actually have 2 lazy loaded modules, the one inside app works, if i comment out the one inside lib then it builds, otherwise you get the error above.

The 2 modules are exactly the same and created for testing, they are using the new way of doing lazy loading of modules in angular 8.

RouterModule.forRoot(
    [{ path: '', loadChildren: () => import("./my-lazy-load/my-lazy-load-routing.module").then(m => m.MyLazyLoadRoutingModule)},
      { path: 'xyz', loadChildren: () => import("../../../../libs/my-test").then(m => m.MyLazyLoadModule)}
    ],
    { initialNavigation: 'enabled', enableTracing: true }
  )

Context

Please provide any relevant information about your setup:

  • version of Nx 8
  • version of Angular CLI 8

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8

github_iconTop GitHub Comments

0reactions
iangregsondevcommented, Jun 8, 2019

@FrozenPandaz Nice catch! - It works!, I am using the workaround. Thank you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular lazy loading not working with ng build --prod
but when building with the command 'ng build --prod' the lazy loading modules are not generated. Thoses are the routing modules : App-routing....
Read more >
Lazy Load Angular Library (Micro-Applications) | by Matt Vaughn
Create a new Workspace. Let's get started by creating a new Nx workspace to work in. I want to have the application and...
Read more >
ASP.NET Core, Angular with Webpack and Visual Studio
This article shows how Webpack could be used together with Visual Studio ASP.NET Core and Angular. Both the client and the server side...
Read more >
nrwl-nx/community - Gitter
@kristofdegrave Hey, I have this situation in our app where we lazy load a lib from the app via routes. loadChildren: () =>...
Read more >
Experimenting With Lazy Loaded Modules, Ahead Of Time ...
Ben Nadel shares the approach to lazy loading modules that he's finally got working with Angular 6.1.7, Webpack 4, and Ahead of Time...
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