Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@tzachbon
Copy link

What kind of change does this PR introduce?

Bug fix

Did you add tests for your changes?

Yes

Summary

This PR fixes issue #16125 where ConsumeSharedModule doesn't properly inherit buildMeta and buildInfo from its fallback module, causing incorrect ESM/CJS detection for .mjs files in Module Federation.

Changes

  • Added finishModules hook in ConsumeSharedPlugin to copy buildMeta and buildInfo from fallback modules to ConsumeSharedModule instances
  • Hook runs at stage 10 (after export analysis by FlagDependencyExportsPlugin)
  • Handles both eager and lazy (async) consumption modes
  • Follows webpack's DelegatedModule pattern for metadata inheritance

Test Coverage

  • Added test case test/configCases/sharing/consume-mjs-module/ to verify ESM module consumption works correctly
  • All existing tests pass (3,700+ ConfigTestCases, 59 sharing tests, 104 container tests, 26,708 unit tests)
  • No regressions detected

Impact

This fix ensures Module Federation correctly handles ESM modules (particularly .mjs files) by preserving the exportsType and other critical metadata through the consumption chain. This resolves issues with packages like swr/infinite and any other shared packages that use .mjs extensions.

Related

Does this PR introduce a breaking change?

No

ConsumeSharedModule now inherits buildMeta and buildInfo from its
fallback module to preserve ESM/CJS detection and export analysis
metadata.

This fix ensures that Module Federation correctly handles ESM modules
(particularly .mjs files) by preserving the exportsType and other
critical metadata through the consumption chain.

The finishModules hook (stage 10) is used to copy metadata after
export analysis is complete, following webpack's DelegatedModule
pattern.

Fixes webpack#16125
@tzachbon
Copy link
Author

Would appreciate your review 🙏🏻 @alexander-akait @ScriptedAlchemy (ty ty)

@codspeed-hq
Copy link

codspeed-hq bot commented Oct 31, 2025

CodSpeed Performance Report

Merging #20054 will degrade performances by 17.44%

Comparing tzachbon:fix/consume-shared-module-buildmeta (2efde38) with main (fd9861a)

Summary

⚡ 3 improvements
❌ 1 regression
✅ 65 untouched

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark BASE HEAD Change
benchmark "cache-filesystem", scenario '{"name":"mode-production","mode":"production"}' 865.4 ms 742.6 ms +16.53%
benchmark "many-modules-commonjs", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' 39.7 ms 48.1 ms -17.44%
benchmark "many-modules-esm", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' 48.9 ms 40.7 ms +20%
benchmark "wasm-modules-async", scenario '{"name":"mode-development","mode":"development"}' 180.9 ms 150.4 ms +20.28%

@naruaway
Copy link
Contributor

naruaway commented Nov 4, 2025

FYI I verified this fixes "federation-local" case in the new repro I created (#16125 (comment))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Resolve module (mjs) incorrectly when using Module Federation Plugin

2 participants