-
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Angular 5 upgrade can't get lazy loading to work #1936
Comments
I experience similar problems, where lazy loading fails when loading angular application. |
@WillooWisp do you have your app compiling properly through webpack? What I did in order to get it to work is change the routes to:
That causes a compile error, but when you trigger a recompile it works fine. Does this work for you? To clarify; I'm stuck at this exact point myself, but at least this way I got to see if the app worked fine after the lazyloading issue was fixed. Would like to see if the same works for you, cause we may have a bug in the way Lazyloading modules are being loaded. |
After some testing and comparing with other issues; I've got Lazyloading to work after disabling the I'd like to get something comparable back again, that'll still be a bit of a puzzle. Anyone who got Lazyloading with separation of |
@Bjeaurn Yes it works for me as well when I use a function (lambda expression) instead of a string for loadChildren. But is that the same thing, will it still be separated into its own chunk and get lazy loaded now when an import of the module exists in the app routing module? |
@Bjeaurn It is strange however that it actually works sometimes with the string syntax "login.module#LoginModule" when rebuilding with webpack and sometimes it does not. It always succeeds during build but sometimes failes during runtime load of modules. |
@Bjeaurn What exactly did you change or remove from the webpack configuration to disable the separation of vendor and polyfills in order to get it to work? |
I didn't necessarily disable the separation, I simply removed the Seeing as the project was based upon this |
I understand, but I no longer have that DllBundlesPlugin after merging in the latest changes from master in this repo, but still experience the lazy loading problems using the string/path syntax. |
What's the error you receive when you try to use the Angular convention for |
global.error-handler.ts:43 Error: Uncaught (in promise): Error: Cannot find module './login/login.module#LoginModule'. |
The strange thing is that some modules work and some does not to lazy load with the string path syntax, but they did work to load this way before. And it varies from time to time when doing a rebuild. |
I think the |
@WillooWisp Have you made any progress in this? If so, can you summarize the actions that helped you. Maybe link to any posts and/or comments that helped. I think we can recommend this issue gets closed; as the main |
I experienced the same issue (new project created with CLI 1.6.0 && Angular 5.1.1). My routes were simple:
|
One more thing: |
@Bjeaurn Lazy loading still does not work as before, and I have made sure I have the correct webpack configuration according to latest on master. I have tried both with "./" and without it in the beginning of the string path to the module without success, so that does not work as it used to. Using the () => Module syntax works however, but is that the exact same thing? I mean will the behavior be the exact same thing regardless of how you import the lazy loaded module, that is importing the Module explicitly and lazy loading it with the () => Module syntax, compared to not importing the Module and using the string path syntax in loadChildren? |
@Bjeaurn I still get this also, "ERROR in TypeError: Cannot read property 'loadChildren' of undefined", upon first compilation using "start:hmr", but a recompile solves this. A little frustrating though, did you work this out? |
@Bjeaurn loadChildren with a function () => Module, does not work with AOT. And according to this, angular/angular-cli#4192, importing the Module that way breaks lazy loading from its own chunk. |
I finally found the problem. I am using conditionals in my app module to include different routes depending on some variable, which has worked perfectly before, but doing that with latest configuration causes the chunks to not get generated for lazy loaded modules. |
So to summarize, you are confirming that The chunks not getting generated properly is more of a Webpack issue in my opinion, although that heavily relies on |
I can confirm that the string path syntax works fine as long as your imports, declarations and routes are static. If code contains conditionals, where some routes are added based on some condition, chunks will not be generated for those upon first compilation, using start:hmr or start:aot. Making any change affecting the main chunk will cause a recompile and chunks will be generated for the lazy loaded routes as well. If those routes in turn contain lazy loaded child routes a recompile must be triggered once again from this parent chunk. It used to work fine with conditionals, both when it came to adding routes more dynamically, but also adding declarations and module imports based on some condition. This is also broken now, so declarations and imports added inside conditional statements are ignored unfortunately. |
Any update or workaround for this? |
I'm also having the same issue. App is getting quite large now and needs lazy loading to keep the initial load time down for the user. I've tried every syntax:
Webpack compiles fine and app works for all of the root-UI and smaller components not using loadChildren, but when nav to '/properties' getting 404 inside the router-outlet Angular CLI: 1.6.3 Also I should note one of the '/properties' child links are using :id but even commenting out all these dynamic links the route never loads. |
It’s unclear what exactly is causing this, but it seems to be related to the |
Compare your webpack config with the one from this repo, make sure you do not have any significant changes. Then it should work as long as you do not have any conditional include of routes, modules or declarations in your code. Unfortunately conditionals do not work anymore, why I do not know. |
Thank you both. I was able to get the lazy loading to work by disabling all the Auth/Services out for conditional login routing and deleting the NodeModule folder and npm update. Need to do more testing to figure out a workaround. If conditionals truly don't work anymore then this completely kills any auth rules for apps. *NgIf still seems to work in the componentHTML files, so thats good. |
Is there any clear solution on this yet? Am getting the same issue on my project. |
The new |
@Televic-Education this appears to be dynamic component loading only and not lazy loading modules. We hit this issue, or maybe a slight variation of it. The above is the original stackoverflow q raised. In short, we want to use modules for pages and not components thus allowing good separation of concerns from redux to routing inc. component importing managed by the module that needs them etc etc. Only lazy loading modules everywhere works just fine, but lazy loading a module inside a module that was not lazy loaded breaks things and the said lazy loading throws an error saying the module cannot be found. I think we narrowed it down to the ang-cli tool simply not creating the chunk. Here is the code https://github.com/jdcrecur/ang5ModuleRouting The router that breaks is: https://github.com/jdcrecur/ang5ModuleRouting/blob/master/src/app/modules/layouts/authenticated/authenticated-layout-routing.module.ts The module is referenced from the base of the app directory, but it doesn't make any difference how this is referenced, either by traversing up or not. |
Same issue here; help is very appreciate |
Same here. |
Same issue. |
There's a tool call |
I have the same problem with angular cli 1.7.0.
|
Be advised that when you upgrade your versions, they will have to match as there is no backwards compatibility from the Angular team within minor versions between modules. So you cannot have The only exception to this rule is If you're using this repo, |
there is my config
|
I had this problem and the cause for mine was DLL plugin. -Add common chunks configuration to plugins: I also noticed in other 'issues' that ContextReplacementPlugin could also be a cause for this. I have some variables in my App module (are the inputs - address and port - for services) which are not known at compile time and that's not a problem for my configuration. |
Looks good, except for By the way, this is not a support forum; maybe we should move all of this to StackOverflow and make a tag for In regards to @jandresampaio, this in a basic sense fixed it for me too; I just checked my current Basically; check your webpack configurations. Try to download a new one and upgrade your After some trial and error, I got my lazy loading to work this way. I suggest we close this thread and any other support request goes onto StackOverflow. |
I also face same issue: ERROR in TypeError: Cannot read property 'loadChildren' of undefined Environment is: 15 "@angular-devkit/core": "0.0.29", |
Not a support forum, do read the last post I made here: #1936 (comment) Check your webpack configuration and refresh it if you're upgrading from an old version of this repo. You will need to check the plugins as well, as some of them have been deprecated. |
finally how can manage it ? , i got the same issues |
At least try to read? #1936 (comment) Reminder: This is not a support forum. |
I had the same issue, and I didn't catch the warning on my terminal holding the ng serve. It seems that add a page while ng serve is running didn't allow to rebuild properly with the new page. |
+1 |
2 similar comments
+1 |
+1 |
in aot : the compiler is missing in the RouterConfigLoader. |
Indeed this was fixed for me using --aot flag but it's not a solution. It looks like when I modified the RouterConfig by adding a new lazy loaded module, everything didn't worked as expected.
Routes for Module A would look like this: Routes for Module B would look like this: |
+1 |
I have the same issue loading
I the case up here the error is
|
ERROR Error: Uncaught (in promise): Error: No NgModule metadata found for 'Component module'.( { path: 'purchaseOrders', loadChildren: '../purchase-order/purchase-order.module#PurchaseOrderModule' }, |
Note: for support questions, please use one of these channels: Chat: AngularClass.slack or Twitter: @AngularClass
I'm submitting a ...
[x] bug report
[ ] feature request
[ ] question about the decisions made in the repository
What is the current behavior?
I've managed to upgrade most of the repository to reflect this one, and get a compiling built out of it. When I try to get lazyloading to work in the way it used to, I run into multiple issues that break the app.
If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem
package.json
webpack.common.config
app.routes
, being loaded throughapp.module
usingRootModule.forRoot(appRoutes)
This one gives me the
Error: Cannot find module '../demo/demo.module'.
If I switch the lazy loading
loadChildren:
toloadChildren: () => HelpModule
, it doesn't compile.What is the expected behavior?
Lazy loading to work, given either of the two solutions.
Please tell us about your environment:
I'll add as I go...
The text was updated successfully, but these errors were encountered: