Unable to lazy load modules - Module cannot be found error #442

Closed
opened 2025-08-09 17:16:18 +00:00 by fergalmoran · 0 comments
Owner

Originally created by @mpalmer-sps on 9/5/2017

Hello, I've created a Github repo here: https://github.com/mpalmer-sps/PluralSightNg2Fundamentals

I'm trying to add a module using a lazy load implementation (learning this) but the Angular documented approach does not work despite the syntax being correct. I'm uncertain if this is (maybe) not supported by the SPATemplates?
The error is the following:
ERROR Error: Uncaught (in promise): Error: Cannot find module 'app/user/user.module'. webpackEmptyContext@http://localhost:3258

The user.module is referenced here in the app.module:
{ path: 'user', loadChildren:'app/user/user.module#UsersModule'},

however, this doesn't work even when trying different path strings.

The workaround for this is to modify the navigation link in the navbar.component.html file to the following:
<a [routerLink]="['/profile']" routerLinkActive="active">Welcome User</a>

Whereas before it was the following:
<a [routerLink]="['/user/profile']" routerLinkActive="active">Welcome User</a>

and then removing the path with the loadChildren syntax and adding the UserModule as shown in the app.module.shared.ts file

Is this is expected behavior when using modules other than the app.module?

*Originally created by @mpalmer-sps on 9/5/2017* Hello, I've created a Github repo here: https://github.com/mpalmer-sps/PluralSightNg2Fundamentals I'm trying to add a module using a lazy load implementation (learning this) but the Angular documented approach does not work despite the syntax being correct. I'm uncertain if this is (maybe) not supported by the SPATemplates? The error is the following: `ERROR Error: Uncaught (in promise): Error: Cannot find module 'app/user/user.module'. webpackEmptyContext@http://localhost:3258` The user.module is referenced here in the app.module: `{ path: 'user', loadChildren:'app/user/user.module#UsersModule'},` however, this doesn't work even when trying different path strings. The workaround for this is to modify the navigation link in the navbar.component.html file to the following: ` <a [routerLink]="['/profile']" routerLinkActive="active">Welcome User</a>` Whereas before it was the following: ` <a [routerLink]="['/user/profile']" routerLinkActive="active">Welcome User</a>` and then removing the path with the loadChildren syntax and adding the UserModule as shown in the app.module.shared.ts file Is this is expected behavior when using modules other than the app.module?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github/JavaScriptServices#442
No description provided.