Skip to content

fix: module library export definitions when multiple runtimes#20179

Merged
alexander-akait merged 1 commit intomainfrom
fix-esm-multi-runtime
Nov 28, 2025
Merged

fix: module library export definitions when multiple runtimes#20179
alexander-akait merged 1 commit intomainfrom
fix-esm-multi-runtime

Conversation

@hai-x
Copy link
Copy Markdown
Member

@hai-x hai-x commented Nov 27, 2025

Summary

What kind of change does this PR introduce?

Fixes #20164.

We should consider different runtimes during code generation. When the module hash varies between runtimes, the code generation will run multiple times. To prevent exports from being overwritten, we should store export sources and finalNames in Map instead of using string.

The PR also

  1. Moves the on-demand generation logic into ModuleLibraryPlugin to make it clearer and library-specific.
  2. Fixes a typo in test/configCases/library/module-useless-export-requirement/entry3.js.

Did you add tests for your changes?

Yes

Does this PR introduce a breaking change?

No

If relevant, what needs to be documented once your changes are merged or what have you already documented?

No

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Nov 27, 2025

This PR is packaged and the instant preview is available (9dc25ca).

Install it locally:

  • npm
npm i -D webpack@https://pkg.pr.new/webpack@9dc25ca
  • yarn
yarn add -D webpack@https://pkg.pr.new/webpack@9dc25ca
  • pnpm
pnpm add -D webpack@https://pkg.pr.new/webpack@9dc25ca

@hai-x hai-x force-pushed the fix-esm-multi-runtime branch from 227c6ba to 9280368 Compare November 27, 2025 17:27
@hai-x hai-x force-pushed the fix-esm-multi-runtime branch from 9280368 to 7fd501d Compare November 27, 2025 17:28
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Nov 27, 2025

CodSpeed Performance Report

Merging #20179 will improve performances by 22.48%

Comparing fix-esm-multi-runtime (7fd501d) with main (4ee190d)

Summary

⚡ 1 improvement
✅ 68 untouched

Benchmarks breakdown

Benchmark BASE HEAD Change
benchmark "three-long", scenario '{"name":"mode-production","mode":"production"}' 3.1 s 2.5 s +22.48%

@hai-x hai-x marked this pull request as ready for review November 27, 2025 18:12
PLUGIN_NAME,
(module, runtimes, source, finalName) => {
/** @type {BuildMeta} */
const buildMeta = module.buildMeta || (module.buildMeta = {});
Copy link
Copy Markdown
Member

@alexander-akait alexander-akait Nov 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sometimes I think we should improve buildMeta and buildInfo types, I think we have it here always, anyway let's do it separately

@alexander-akait alexander-akait merged commit 9dc25ca into main Nov 28, 2025
91 of 92 checks passed
@alexander-akait alexander-akait deleted the fix-esm-multi-runtime branch November 28, 2025 09:10
@ShenHongFei
Copy link
Copy Markdown
Contributor

After updating webpack@https://pkg.pr.new/webpack@9dc25ca, I tested it in the actual project and it works normally. Thank you.

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.

Regression: imported function is undefined when multi-entry;

3 participants