Minimal reproduction for a regression in webpack 5.105.4 where ModuleConcatenationPlugin
(scope hoisting) throws:
Target module of reexport from '...' is not part of the concatenation (export 'TagAppearance')
packages/
lib-a/ # Exports `Appearance` (analogous to @jotunheim/react-tag)
lib-b/ # Imports from lib-a and re-exports `TagAppearance`
# Also imports from lib-c, lib-d, lib-e (non-shared helpers)
lib-c/ # Non-shared helper (concatenatable with lib-b)
lib-d/ # Non-shared helper (concatenatable with lib-b)
lib-e/ # Non-shared helper (concatenatable with lib-b)
src/
index.js # App entry — imports { createTable, TagAppearance } from lib-b
Key ingredients:
- Both
lib-aandlib-bare Module Federation shared dependencies lib-c,lib-d,lib-eare not shared — webpack can concatenate them withlib-blib-bre-exportsTagAppearancefromlib-a
When webpack builds in production mode, ModuleConcatenationPlugin concatenates
lib-b + lib-c + lib-d + lib-e into one scope-hoisted module. But lib-a is a
ConsumeSharedModule (Module Federation) and is not part of that concatenation.
When webpack tries to resolve the re-export of TagAppearance (lib-b -> lib-a),
it can't find the target module in the concatenation and throws.
npm install
npm run build # FAILS on webpack 5.105.4
npm run build:ok # PASSES (workaround: concatenateModules: false)npm install webpack@5.105.3
npm run build # PASSES on webpack 5.105.3Two changes in webpack 5.105.4 affect module concatenation:
// ConcatenatedModule.js ~line 1007 (5.105.4)
+ if (!connection.module.getSourceBasicTypes().has(JAVASCRIPT_TYPE)) {
+ return false;
+ }This new guard filters out modules whose getSourceBasicTypes() doesn't include
"javascript". A ConsumeSharedModule likely doesn't report "javascript" as a
basic source type, so it gets excluded when resolving reexport targets via findTarget().
This causes findTarget() to return false, triggering the error in getFinalBinding().
// ModuleConcatenationPlugin.js ~line 469
- if (sourceTypes.size === 1) {
+ if (sourceTypes.size === 1 && sourceTypes.has(JAVASCRIPT_TYPE)) {This change tightens when concatenated modules get disconnected from chunks, which may affect which modules remain visible during code generation.
- Pin webpack to 5.105.3 — simplest, no side effects
- Disable scope hoisting:
optimization: { concatenateModules: false }— larger bundles (~5-15%) - Fix the upstream library so it doesn't re-export from a separate shared package