-
Notifications
You must be signed in to change notification settings - Fork 12k
Creating ROUTES with custom factory function ends up with "Cannot read property 'loadChildren' of undefined" error #9913
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
Comments
OK, I've followed the stack trace and think I've found what causes the bug. I think it's because of this code in the angular/compiler's source:
According to the stacktrace, it fails on Obviously, this provider has no |
As this appears to be a defect in the Angular code itself, can you please open an issue here with a summary of your findings. And please reference this issue as well. |
I agree that this appears to be an issue with Angular itself and not the CLI, so I am closing this issue. |
Related to #9343 |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Uh oh!
There was an error while loading. Please reload this page.
Versions
Repro steps
We have a custom webpack setup that uses
@ngtools/webpack
. Everything has been working good for us so far, in both JiT and AoT. Right now we are trying to setup lazy routes.We wanted to implement them using the standard way (
loadChildren: '../features/dashboard/dashboard.module#DashboardFeatureModule'
), but it just didn't work. (We tried and checked everything.) Anyways, it doesn't matter, because loadChildren can accept a function returning a promise with ngModule. So we decided to load the module ourselves.Example:
Observed behavior
It fails with the following error during the first compilation in JiT and in any compilation in AoT:
(It leaves no stacktrace).
In JiT with webpack-dev-server, if you trigger a recompilation (by changing any file), it compiles correctly since the 2nd compilation and on every following one.
Seems like angular's compiler has some trouble while trying to parse our factory function. Should it parse it at all? I think we don't need the compiler to parse it all. Do you know any workaround, so we can fix the error, so the compiler parses it correctly or just doesn't try to parse it at all?
Desired behavior
Defining routes with a custom
FactoryProvider
should just work.It lets you to easily implement lazy loaded modules with a custom way.
Additional note
If we downgrade to angular 5.2.5 and ngtools/webpack 1.10.0, then it behaves in the same way, but the error includes a stacktrace as well:
The text was updated successfully, but these errors were encountered: