Skip to content
This repository was archived by the owner on Apr 8, 2020. It is now read-only.

Lazy loading doesn't seem to be working #1194

Closed
frederikprijck opened this issue Aug 15, 2017 · 12 comments
Closed

Lazy loading doesn't seem to be working #1194

frederikprijck opened this issue Aug 15, 2017 · 12 comments

Comments

@frederikprijck
Copy link
Contributor

frederikprijck commented Aug 15, 2017

Hi,

I've been looking into ASP.NET Core 2.0 and the Angular template available in VS 2017.
A fresh install works fine, but it looks like there's no example using lazy-loading.

I wanted to try implement it based on 7ded0a0 .
In order to do so I've created a repository (using the default starter from VS2017) and added the following commit: https://github.com/frederikprijck/aspnet-angular-lazy-loading/commit/0edaa0889e1084dfad47d1674641b86c0e45332c

Note: I've disabled development build to ensure @ngtools/webpack was used.

Running the project available in the repository (https://github.com/frederikprijck/aspnet-angular-lazy-loading) results in the following error when navigating to counter.

Error: Uncaught (in promise): Error: Cannot find module './components/counter/counter.module.ngfactory'.
Error: Cannot find module './components/counter/counter.module.ngfactory'.
at webpackEmptyContext

Does the template require more changes in order to enable Lazy Loading?

Thanks

@frederikprijck
Copy link
Contributor Author

frederikprijck commented Aug 15, 2017

I managed to find the cause of the error.

First of all, it was incorrect of me to try and use @ngtools/webpack. According to @MarkPieszak the starter does not support it in dev build.

So in order to use Lazy Loading in dev mode, I had to npm install angular2-router-loader and add it to the webpack config. This seems to be missing from the template.

I added a PR which fixes it.

@MarkPieszak
Copy link
Contributor

We can't make any updates until the next quarter to the templates provided with dotnetcore 2.0, right @SteveSandersonMS ?

It'd be nice to have angular2-router-loader as a default for the Dev builds so others won't run into the same thing. I must of missed that one when looking at everything, apologies!

@SteveSandersonMS
Copy link
Member

Thanks for reporting this! Closing this one in favour of #1195.

We can't make any updates until the next quarter to the templates provided with dotnetcore 2.0, right @SteveSandersonMS ?

We can make changes in the repo here any time, but when they actually ship in an updated .NET SDK depends on the .NET SDK shipping schedule :)

@MarkPieszak
Copy link
Contributor

Excellent, yeah that's what I figured, great 👍

SteveSandersonMS pushed a commit that referenced this issue Aug 21, 2017
Previously, the AngularSpa didn't include `angular2-router-loader`.
This commit ensures it does.

Closes #1194
@ilennert
Copy link

Yes, had this problem. Glad I found this thread.... Dropped in the code as per #1195. Worked like a charm!

@naveedahmed1
Copy link

naveedahmed1 commented Sep 3, 2017

It seems that angular2-router-loader is now angular-router-loader. But I tried to install angular-router-loader by following the instructions mentioned at https://www.npmjs.com/package/angular-router-loader, but it didnt work.

It seems that this package has a dependency on loader-utils , which npm was unable to install.

Can you please take a look?

@chsakell
Copy link

I used the same template ASP.NET Core 2 & Angular in VS 2017 with lazy loading. It works good in dev mode after adding angular2-router-loader, it passes the production build (dotnet publish -c Release) but when deployed on Azure App Service I get the same error (ERROR Error: Uncaught (in promise): Error: Cannot find module './product/product.module.ngfactory'.).

webpack.config.js has the following line:

{ test: /\.ts$/, include: /ClientApp/, use: isDevBuild ? ['awesome-typescript-loader?silent=true', 'angular2-template-loader', 'angular2-router-loader'] : '@ngtools/webpack' }

Doesn't this mean that ngtools/webpack causes the problem? Is there any workaround for this?

@fen89
Copy link

fen89 commented Dec 1, 2017

@chsakell I have exact the same problem, dev build mode fine, production build builds fine but as soon as I start the generated project and call my lazy module I get the same error... did you find a solution?

@chsakell
Copy link

chsakell commented Dec 1, 2017

Yes @fen89 , just use the same config for both dev and prod in webpack.config.js.

{ test: /\.ts$/, include: /ClientApp/, use: ['awesome-typescript-loader?silent=true', 'angular2-template-loader', 'angular2-router-loader'] },

That worked for me.

@darlontrofy
Copy link

Is there any solution to this? I'm having the same problem today for the past 1 week..

@JihedHalimi
Copy link

We have the exact same problem with angular 6.1 AspNet Core and Azue App Service. @darlontrofy did you find a solution?

@naveedahmed1
Copy link

Try the new template.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants