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

Most upvoted comments

I switched back to the original configuration and it works like a charm now.

great. released as 5.3.0

@sokra Does this help

ERROR in ./src/framework/SplitViewModule/configuration.ts
str.replace is not a function
TypeError: str.replace is not a function
    at quoteMeta (/Users/doberkofler/MyDev/ljs_app/trunk/periscope/node_modules/webpack/lib/util/compileBooleanMatcher.js:9:13)
    at Function.from (<anonymous>)
    at itemsToRegexp (/Users/doberkofler/MyDev/ljs_app/trunk/periscope/node_modules/webpack/lib/util/compileBooleanMatcher.js:195:49)
    at Function.compileBooleanMatcherFromLists [as fromLists] (/Users/doberkofler/MyDev/ljs_app/trunk/periscope/node_modules/webpack/lib/util/compileBooleanMatcher.js:41:25)
    at RuntimeTemplate.runtimeConditionExpression (/Users/doberkofler/MyDev/ljs_app/trunk/periscope/node_modules/webpack/lib/RuntimeTemplate.js:592:32)
    at RuntimeTemplate.importStatement (/Users/doberkofler/MyDev/ljs_app/trunk/periscope/node_modules/webpack/lib/RuntimeTemplate.js:625:28)
    at HarmonyImportSpecifierDependency.getImportStatement (/Users/doberkofler/MyDev/ljs_app/trunk/periscope/node_modules/webpack/lib/dependencies/HarmonyImportDependency.js:90:26)
    at HarmonyImportSpecifierDependencyTemplate.apply (/Users/doberkofler/MyDev/ljs_app/trunk/periscope/node_modules/webpack/lib/dependencies/HarmonyImportDependency.js:290:31)
    at HarmonyImportSpecifierDependencyTemplate.apply (/Users/doberkofler/MyDev/ljs_app/trunk/periscope/node_modules/webpack/lib/dependencies/HarmonyImportSpecifierDependency.js:298:10)
    at JavascriptGenerator.sourceDependency (/Users/doberkofler/MyDev/ljs_app/trunk/periscope/node_modules/webpack/lib/javascript/JavascriptGenerator.js:203:12)
    at JavascriptGenerator.sourceModule (/Users/doberkofler/MyDev/ljs_app/trunk/periscope/node_modules/webpack/lib/javascript/JavascriptGenerator.js:112:9)
    at JavascriptGenerator.generate (/Users/doberkofler/MyDev/ljs_app/trunk/periscope/node_modules/webpack/lib/javascript/JavascriptGenerator.js:98:8)
    at NormalModule.codeGeneration (/Users/doberkofler/MyDev/ljs_app/trunk/periscope/node_modules/webpack/lib/NormalModule.js:924:22)
    at /Users/doberkofler/MyDev/ljs_app/trunk/periscope/node_modules/webpack/lib/Compilation.js:2147:24
    at /Users/doberkofler/MyDev/ljs_app/trunk/periscope/node_modules/webpack/lib/CacheFacade.js:51:43
    at /Users/doberkofler/MyDev/ljs_app/trunk/periscope/node_modules/webpack/lib/Cache.js:93:5
 @ ./src/framework/SplitViewModule/index.ts 9:0-56 104:22-43
 @ ./src/modules/las_mod_user/index.ts 21:0-79 40:32-47 134:21-36 135:21-36 138:21-35 141:21-36 187:96-110 188:27-41 283:17-32 293:17-32 323:17-31 327:17-32