webpack: splitChunks with innerGraph does not add required dependencies into common chunk
Bug report
What is the current behavior?
Two entries and common chunk (see the linked repo for more details):
- index1 - imports dep1 which imports dep2. actually uses both of them
- index2 - imports dep1 but only uses a function that does not depend on dep2
- commons - contains everything that is used by more than one entry
The issue is that dep2 is detected only as required only for index1 (since index2 does not actually use it). By itself that is kind of fine - when loading commons+index1, everything works, because dep2 is loaded from index1 chunk.
However when loading index2, fails with runtime error due to the fact that in commons chunk, dep1 still lists dep2 as dependency - but it is not included in either commons or index2.
If the current behavior is a bug, please provide the steps to reproduce.
https://github.com/Knagis/webpack-concat-issue/tree/commons-error
What is the expected behavior?
no runtime errors (either dep2 is included in commons chunk or it is loaded only when calling the function that uses it or various other combinations of moving/splitting the modules so that it works for both entries)
Other relevant information: webpack version: 5.1.3 Node.js version: 12.13.1 Operating System: Win10 Additional tools:
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 40 (24 by maintainers)
Commits related to this issue
- generate code that executes depending on runtime fixes #11770 — committed to webpack/webpack by sokra 4 years ago
- generate code that executes depending on runtime fixes #11770 — committed to webpack/webpack by sokra 4 years ago
- generate code that executes depending on runtime fixes #11770 — committed to webpack/webpack by sokra 4 years ago
- generate code that executes depending on runtime fixes #11770 — committed to webpack/webpack by sokra 4 years ago
- generate code that executes depending on runtime fixes #11770 — committed to webpack/webpack by sokra 4 years ago
great. released as 5.3.0
@sokra Does this help