question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to lazy load modules and their dependencies when using barrel(s)

See original GitHub issue

I’m submitting a…


[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report  
[ ] Feature request
[ ] Documentation issue or request

Current behavior

We’re trying to lazy-load by cherry picking specific modules related to a particular route.

Example: Npm package: ui.common with LoginModule, RegisterModule and AdminModule in a flat esm5 index.js.

We want to lazy-load: /admin -> only AdminModule and its dependencies should be loaded /login -> only LoginModule and its dependencies should be loaded. /register -> only RegisterModule and its dependencies should be loaded.

The JS chunks are being generated as in the attached image below. (Refer to dist/)

capture

What we’ve also noticed is when loading the last registered route, in this case register, it loads the required JS chunk. However when navigating to admin or login it loads the incorrect chunk with the following error Error: Cannot find ‘LoginModule’ in ‘./common/index’ (please refer to the image below).

capture4

Expected behavior

I expect that the necessary modules are lazy loaded for a specific route.

Minimal reproduction of the problem with instructions

GitHub Repo: https://github.com/Lydon/lazy-loading Navigate to admin or login, otherwise refer to the attached images.

Environment


Angular version: 5.2.X


Browser:
- [ ] Chrome (desktop) version XX
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
- [x] All
 
For Tooling issues:
- Angular CLI 1.7.1
- Node version:  8.4.0
- Platform:  Windows

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:3
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
filipesilvacommented, Mar 12, 2018

Heya, sorry for taking a while to answer. Yes this sounds like a bug in ngtools/webpack, as reported in https://github.com/angular/angular-cli/issues/9862. I think we’ve actually fixed it in master for 6.x, but will comment there.

1reaction
peterbakonyi05commented, Mar 1, 2018

@alexeagle It happens using @ngtools/webpack with a custom Webpack configuration. So if it is CLI related, it is probably @ngtools/webpack

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular Lazy Loaded module dependencies (Encountered ...
ERROR in: Encountered undefined provider! Usually, this means you have a circular dependency (might be caused by using 'barrel' index.ts files.
Read more >
How to Nest Lazy-Loaded Modules - DEV Community ‍ ‍
The module, its components, and all of its dependencies will not load to the client until the user navigates to this route. alt...
Read more >
Common errors - FAQ - A progressive Node.js framework
During your development with NestJS, you may encounter various errors as you learn the framework. "Cannot resolve dependency" error#. Probably the most common ......
Read more >
aws-cdk-lib module - AWS Documentation
When upgrading from CDK 1.x, remove all dependencies to individual CDK packages from your dependencies file and follow the rest of the sections....
Read more >
Providing Module Configuration Using forRoot() And Ahead ...
The fix for us was to add the module export also to the public_api.ts file of the library and imported it from there:...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found