-
Notifications
You must be signed in to change notification settings - Fork 12k
Let 'lazyModules' option support modules from outside root in AOT mode #12859
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
To lazy load a library you need to use the library name to import, the one in your For example
See here for more context: |
Yes, so I had tried a few different versions already.... The library I want to lazy load is actually located in
Apart from that, also the version I posted above (with the proxy module) doesn't work when I specify it with the module class name and a # at the end. Everything returns an error like
The implementing PR #9515 also does't put the # and the module class name in the lazyModules option by the way. In the same PR it is said that the paths are relative to the "root" setting, which by default is "" as opposed to sourceRoot, which by default is "src". That's obviously why the "proxy" is working with src/app/... and without the #. (see this PR angular/devkit#755, where the path in the test was fixed to also include the "src" part). When I looked in the code I could not find any special handling so I still expect this to be a feature request (or a bug if it should have worked). |
What might be worth noting is that I'm compiling with AOT and that for example specifying something like the following in JIT mode DOES work!
So it might be related to #8142 and #6373 (but that seems to be specifically about lazy loading in the router of a library) |
I have the same problem and built a super small angular 7 repository to reproduce it: https://github.com/totkeks/angular-bugs/tree/bug/lazy-route-no-factory My analysis so far is, that the ngfactory is not being built by the angular (typescript) compiler. Because the error message comes from the webpack bundler, which is correctly identifying the lazy loaded route and tries to load the ngfactory and bundle it into a separate chunk to be lazy loaded in the application at a later point. Unfortunately digging into angular/cli and angular/compiler was not very successful for me. If anyone could help me set up the breakpoints in vscode with the typescript sources of the angular compiler, then I could continue digging. |
I'm using I'm thinking that this issue is related, since i'm getting the same error after updating ( For now i resolved my issue by migrating back to |
Relates to #6373 |
Closing this in favour of #6373 (comment) |
If anyone needs help lazy loading modules and need something that isn't a route change, please check this out: https://www.npmjs.com/package/@herodevs/lazy-af It's a component that makes it drop-dead simple to lazy load modules on demand. It's literally easier than the |
@aaronfrost it only doesn't solve the issue I created this feature request for: be able to use the lazyModules option to lazily load a module from outside your project root (e.g. from node_modules) in AOT mode. It still needs the same workaround (create a proxy module). It also uses Angular internal API and therefore is just another workaround. Nice work, but no silver bullet :) |
@woppa684 have you found a possible solution for arrow function declaration with AOT |
No, I don't use the router... |
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. |
Bug Report or Feature Request (mark with an
x
)Command (mark with an
x
)Versions
Repro steps
The addition of the 'lazyModules' option was something that people have been asking for for quite some time (to not "abuse" to router to create chunks). Unfortunately the lazyModules option still requires the module to be in the src folder, and therefore it is not possible to lazy load a module from a component library or an external dependency in node_modules. At the moment te only way to achieve this is to create another module that is somewhere under the src folder and imports the external module.
This works:
and this doesn't
The log given by the failure
It curently fails with something like
Desired functionality
lazyModules also supports including modules from node_modules and projects folders.
The text was updated successfully, but these errors were encountered: