Skip to content

satispunk/mf-enhanced-repro

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

webpack 5.105.4 — ModuleConcatenationPlugin crash with Module Federation shared re-exports

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')

Structure

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-a and lib-b are Module Federation shared dependencies
  • lib-c, lib-d, lib-e are not shared — webpack can concatenate them with lib-b
  • lib-b re-exports TagAppearance from lib-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.

Reproduce

npm install
npm run build        # FAILS on webpack 5.105.4
npm run build:ok     # PASSES (workaround: concatenateModules: false)

Verify it works on 5.105.3

npm install webpack@5.105.3
npm run build        # PASSES on webpack 5.105.3

Root cause

Two changes in webpack 5.105.4 affect module concatenation:

1. ConcatenatedModule.js — new filter on getSourceBasicTypes

// 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().

2. ModuleConcatenationPlugin.js — stricter disconnect condition

// 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.

Workarounds

  1. Pin webpack to 5.105.3 — simplest, no side effects
  2. Disable scope hoisting: optimization: { concatenateModules: false } — larger bundles (~5-15%)
  3. Fix the upstream library so it doesn't re-export from a separate shared package

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors