angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

AOT build produces applications unable to lazy load modules

Open slmyers opened this issue 10 years ago • 54 comments

angular-cli: 1.0.0-beta.16
node: 6.0.0
os: linux x64

reproduction repo can be found here

The log given by the failure.

main.cfeed71….bundle.js:547 EXCEPTION: Uncaught (in promise): Error: Cannot find module 
'app/lazy/lazy.module.ngfactory'.

It seems that aot option can not build project that lazily loads modules. I would hope that one could use the patterns in the official documentation -- which I believe I'm doing -- and use the -- aot option to compile your app easily. I would appreciate any clarification as to whether this is an issue with the CLI or with the compiler. Thanks.

slmyers avatar Sep 30 '16 23:09 slmyers

I cleared node_modules, rebuilt project and some clean ups and now gone, so ok so far thanks, Sean

born2net avatar Jan 27 '17 13:01 born2net

i have faced same issue but i solved it by doing following 2 things:

i have added ./ as prefix of html and css in every component file.

i am also using lazy loaded modules, so was exporting module class as default i removed default from export default class AdminModule and i have added

{ path: 'dashboard', loadChildren: 'app/admin/dashboard/dashboard.module#DashboardModule' },

and its working for me.

imVinayPandya avatar Feb 15 '17 11:02 imVinayPandya

No solution???

IAMtheIAM avatar Aug 09 '17 18:08 IAMtheIAM

This has been fixed for quite some time now. Update angular and angular cli. Don't have to mess with the generator anymore either.

On Wed, Aug 9, 2017, 11:27 AM IAMtheIAM [email protected] wrote:

No solution???

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/angular/angular-cli/issues/2452#issuecomment-321341278, or mute the thread https://github.com/notifications/unsubscribe-auth/AAS3eYSr13dV5cBRaUIPMVppVJMno041ks5sWfoKgaJpZM4KLlyv .

Rosseyn avatar Aug 09 '17 20:08 Rosseyn

I'm experiencing a regression with Angular 5.0.0-rc.9 and CLI v1.5.0-rc.8

wbhob avatar Nov 01 '17 04:11 wbhob

Could you give more info?

Are you getting an error? Is it completing without issue but not lazy loading?

One thing you do need to make sure of when lazy loading prod builds now is to include @Component({ moduleId: module.id }) in all of your components.

On Tue, Oct 31, 2017, 9:24 PM Wilson Hobbs [email protected] wrote:

I'm experiencing a regression with Angular 5.0.0-rc.9 and CLI v1.5.0-rc.8

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/angular/angular-cli/issues/2452#issuecomment-340974772, or mute the thread https://github.com/notifications/unsubscribe-auth/AAS3ebnrWR_YnXnxWzGSN7FkIV3qyoQbks5sx_JrgaJpZM4KLlyv .

Rosseyn avatar Nov 01 '17 04:11 Rosseyn

Woah what is that @Rosseyn I have never seen the moduleId thing

wbhob avatar Nov 01 '17 04:11 wbhob

It's been around for a long while but doesn't seem to show up much in documentation. Recently set up a new project and after enabling lazy load, had to find this out the hard way for myself.

Does it solve the issue you're encountering?

On Tue, Oct 31, 2017, 9:45 PM Wilson Hobbs [email protected] wrote:

Woah what is that @Rosseyn https://github.com/rosseyn I have never seen the moduleId thing

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/angular/angular-cli/issues/2452#issuecomment-340976937, or mute the thread https://github.com/notifications/unsubscribe-auth/AAS3eRBbMFmfM6nTcb4rNQPp5e8kYFbDks5sx_dOgaJpZM4KLlyv .

Rosseyn avatar Nov 01 '17 04:11 Rosseyn

Hi all! Do you have any update on this issue? I've tried all workaround suggested but none of those worked for me.

andresmino avatar Nov 03 '17 17:11 andresmino

In Angular v5, what I've found is you can't terminate the file name with .ts.

So if your RoutingModule is AuthRoutingModule in ./auth/auth-routing.module.ts, your loadChildren would be './auth/auth-routing.module#AuthRoutingModule.

wbhob avatar Nov 03 '17 21:11 wbhob

When updating to from Angular 4 to Angular 5 i kept getting

ERROR in Error: Could not resolve module [module path] relative to [routing module path]

for lazy loaded modules. Removing the .ts suffix as @wbhob suggested works.

michaelkrone avatar Nov 22 '17 13:11 michaelkrone

@wbhob you are my hero! was that mentioned anywhere in breaking changes???

ctaepper avatar Nov 24 '17 10:11 ctaepper

I had no idea it ever worked with the extension. I've never put the extension, as far as I can remember (at least since they've moved the CLI to webpack, so way back before even ending v2 releases and moving to Angular v4 I think). As for the "deprecation", I don't remember even seeing an example using the extension in the official docs, so there would be no deprecation to be mentioned. But I could be wrong, if my memory isn't as good as I think it is.

NgxDev avatar Nov 24 '17 17:11 NgxDev

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.