[AOT] [Lazy Loading] Error: Cannot find module './routes/home/home.module.ngfactory'.
See original GitHub issueVersions
@ngtools/webpack 1.8.2
node 8.9.1
npm 5.5.1
webpack 3.8.1
angular 5.0.2
Repro steps
Apologies if this is a duplicate, or a simple configuration issue, but I really can’t progress this any further myself. During an attempt to convert our project into an AOT production build I have run into these errors. I have created a stub version of it here to demonstrate the issue: https://github.com/strongpauly/angular-5-aot-lazy
Installing this project and compiling using JIT works as expected - the two routes, root (or home) and lazy, load correctly.
Using AOT causes the below error message when navigating to the root url.
Observed behavior
Error thrown.
app.df2918c1fc6f0b8f449f.js:1 ERROR Error: Uncaught (in promise): Error: Cannot find module './routes/home/home.module.ngfactory'.
Error: Cannot find module './routes/home/home.module.ngfactory'.
at app.df2918c1fc6f0b8f449f.js:1
at ZoneDelegate.invoke (polyfills.df2918c1fc6f0b8f449f.js:1)
at Object.onInvoke (app.df2918c1fc6f0b8f449f.js:1)
at ZoneDelegate.invoke (polyfills.df2918c1fc6f0b8f449f.js:1)
at Zone.run (polyfills.df2918c1fc6f0b8f449f.js:1)
at polyfills.df2918c1fc6f0b8f449f.js:1
at ZoneDelegate.invokeTask (polyfills.df2918c1fc6f0b8f449f.js:1)
at Object.onInvokeTask (app.df2918c1fc6f0b8f449f.js:1)
at ZoneDelegate.invokeTask (polyfills.df2918c1fc6f0b8f449f.js:1)
at Zone.runTask (polyfills.df2918c1fc6f0b8f449f.js:1)
at app.df2918c1fc6f0b8f449f.js:1
at ZoneDelegate.invoke (polyfills.df2918c1fc6f0b8f449f.js:1)
at Object.onInvoke (app.df2918c1fc6f0b8f449f.js:1)
at ZoneDelegate.invoke (polyfills.df2918c1fc6f0b8f449f.js:1)
at Zone.run (polyfills.df2918c1fc6f0b8f449f.js:1)
at polyfills.df2918c1fc6f0b8f449f.js:1
at ZoneDelegate.invokeTask (polyfills.df2918c1fc6f0b8f449f.js:1)
at Object.onInvokeTask (app.df2918c1fc6f0b8f449f.js:1)
at ZoneDelegate.invokeTask (polyfills.df2918c1fc6f0b8f449f.js:1)
at Zone.runTask (polyfills.df2918c1fc6f0b8f449f.js:1)
at resolvePromise (polyfills.df2918c1fc6f0b8f449f.js:1)
at resolvePromise (polyfills.df2918c1fc6f0b8f449f.js:1)
at polyfills.df2918c1fc6f0b8f449f.js:1
at ZoneDelegate.invokeTask (polyfills.df2918c1fc6f0b8f449f.js:1)
at Object.onInvokeTask (app.df2918c1fc6f0b8f449f.js:1)
at ZoneDelegate.invokeTask (polyfills.df2918c1fc6f0b8f449f.js:1)
at Zone.runTask (polyfills.df2918c1fc6f0b8f449f.js:1)
at drainMicroTaskQueue (polyfills.df2918c1fc6f0b8f449f.js:1)
at <anonymous>
Desired behavior
AOT should load routes lazily in the same way as JIT.
This may have been easier to debug, either with actual documentation specific to ngtools/webpack or with a way to output intermediate files on a failure, but I see there is a separate issue for that.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:3
- Comments:7 (3 by maintainers)
In your
webpack.common.js
file you have this:You are telling Webpack that lazy modules loaded from
@angular/core
should be looked for elsewhere. Since@ngtools/webpack
already does automatically, you are breaking lazy module detection.Just remove this plugin and the lazy chunks (
0.a5ae6789318cbedfbbc1.chunk.js
and1.a5ae6789318cbedfbbc1.chunk.js
) will be built correctly:Note: I wasn’t able to test your app in the browser because your npm scripts don’t work on windows, but I tested
build:client:aot
to make sure the lazy chunks were there.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.