Skip to content

ConsumeSharedModule missing getSourceBasicTypes() causes crash with webpack 5.105.4 #4559

@satispunk

Description

@satispunk

Describe the bug

What is the current behavior?
When using @module-federation/enhanced with webpack 5.105.4, production builds crash with:

ERROR in ./packages/lib-b/index.js + 3 modules
Target module of reexport from '...' is not part of the concatenation (export 'TagAppearance')
This happens when:

Library B is a shared Module Federation dependency

Library A is also a shared Module Federation dependency

Library B re-exports a value from Library A (export { TagAppearance } from 'lib-a')

Library B also imports from other non-shared libraries (lib-c, lib-d, lib-e)

Webpack's ModuleConcatenationPlugin concatenates lib-b with the non-shared libs (scope hoisting), but when it tries to resolve the re-export chain from lib-b → lib-a, it fails because lib-a's ConsumeSharedModule is excluded from target resolution.

What is the expected behavior?
The build should succeed, as it does with webpack 5.105.3.

Root cause
Webpack 5.105.4 added a new getSourceBasicTypes() API (PR #20546 and a corresponding filter in ConcatenatedModule.js (~line 1007):

if (!connection.module.getSourceBasicTypes().has("javascript")) {
return false;
}
Webpack's own ConsumeSharedModule was updated to implement this API correctly:

// webpack/lib/sharing/ConsumeSharedModule.js
getSourceBasicTypes() {
return JAVASCRIPT_TYPES; // Set(["javascript"])
}
However, @module-federation/enhanced's ConsumeSharedModule does not override getSourceBasicTypes(). It only implements getSourceTypes() which returns Set(["consume-shared"]). Since the base Module.getSourceBasicTypes() falls back to this.getSourceTypes(), it returns Set(["consume-shared"]) instead of Set(["javascript"]).

This causes the new filter to exclude MF enhanced's ConsumeSharedModule from reexport target resolution in findTarget(), which returns false, triggering the error in getFinalBinding().

Suggested fix
Add getSourceBasicTypes() to @module-federation/enhanced's ConsumeSharedModule:

const JAVASCRIPT_TYPES = new Set(["javascript"]);

getSourceBasicTypes() {
return JAVASCRIPT_TYPES;
}
This matches what webpack core's ConsumeSharedModule already does.

Steps to reproduce
https://github.com/satispunk/mf-enhanced-repro
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 5.105.3

 "@module-federation/enhanced": "2.2.2", "webpack": "5.105.4", 

Reproduction

https://github.com/satispunk/mf-enhanced-repro

Used Package Manager

npm

System Info

System: OS: Linux 5.15 Ubuntu 22.04.5 LTS 22.04.5 LTS (Jammy Jellyfish) CPU: (8) x64 AMD EPYC Memory: 29.41 GB / 31.36 GB Container: Yes Shell: 5.1.16 - /bin/bash Binaries: Node: 22.21.1 - /home/ubuntu/.nvm/versions/node/v22.21.1/bin/node npm: 10.8.3 - /home/ubuntu/.nvm/versions/node/v22.21.1/bin/npm

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions