-
Notifications
You must be signed in to change notification settings - Fork 519
Unable to lazy load modules - Module cannot be found error #1258
Comments
Since this is an Angular usage question, could you raise this with the Angular community or see what they have in docs? The templates here supply a typical Webpack+Angular starting point, but I'm afraid we don't have the capacity to also take on usage questions for third-party frameworks and packages.
The templates here don't affect what is or isn't supported, as they are not doing anything at runtime. Hope that's OK! |
Thanks @SteveSandersonMS , The problem is that using the SPATemplates, with the file structure that is leveraged being so far outside of the 'norm' for Angular development, puts me in a no-man's land for support. The Microsoft side of the house will point to the Angular side and say "the problem must be over there".. Inversely, the Angular side of the house will take one look at the project structure and throw their hands in the air because the project structure with app.modules split into three files just to start is extremely difficult to trace where the actual issue sits. In the end I may just simply have to abandon this approach of using Visual Studio 2017 and the SPATemplates because of that lack of support for what should be a basic Angular implementation in favor of something that is alot more "normal" in the Angular world. Thanks |
@SteveSandersonMS I've tried every possible option to load this Module leveraging the loadChildren method and it doesn't work. Would it be possible that you can provide a super simple example in a "Hello World" way where the loadChildren method is able to find the module? |
You should have it being a relative path, so ./user/user.module#UserModule. Then make sure your module there has its routes set up correctly. Like in this example: https://github.com/MarkPieszak/aspnetcore-angular2-universal/blob/master/ClientApp/app/containers/lazy/lazy.module.ts Hope that helps! |
Thanks @MarkPieszak |
@MarkPieszak there is a line here where a Module is lazy loaded by referencing the module after it was already resolved with an import statement as in this example:
then it was referenced in his code in this way:
So I took this and applied it to my users module in this way within app.module.shared:
and then added the route as shown below...
This seemed to work but I wanted to test and be 100% certain that the module and components were not being loaded until I clicked the appropriate navlink. Testing this with the network tab on FireFox and Chrome didn't work because of bundling of the JS files into a larger bundle (vendor.js). So, I placed a pair of constructors in the User Module class and the Profile class that wrote to the console once they loaded and it looks like its working (at least there are no errors). I'm still scratching my head as to why the syntax you have in your solution works and mine seems to fail, furthermore, I don't fully understand if this approach I've taken is "valid" and produces the benefits of lazy loading that I'm hoping to incorporate. |
Comment out following line from webpack.config.js Then lazy loaded chunks will be generated for AoT builds. |
@davidsekar This saved my day. Thank you. @SteveSandersonMS is this a reason that "mainFields" line is in there? If not, it should likely be removed from the template. |
@dloukola It was necessary at some point in the past to make server-side prerendering work correctly. If it's no longer necessary (perhaps third-party libraries have changed) then you can certainly remove it. The next update to the Angular template eliminates |
@SteveSandersonMS This is great news about the removal of webpack. Do you have any estimate on when we can expect to see that go into the template? |
Please see #1288 for full details. There isn't a specific ETA for release, but hopefully we will have a preview out in about a month. |
@davidsekar I was able to get my 0-chunk.js file to generate after commenting that line of code out. However, I do not see that file loading in the Network tab at all but yet my module still seems to run fine. Does the chunk get picked up by main-client and main-server? Here is my webpack
|
The angular documentation says loadChildren: 'app/customers/customers.module#CustomersModule'. |
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?
The text was updated successfully, but these errors were encountered: