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

Skip to content

fix: tree-shake unused default export in dynamic-reexport mode#20557

Open
shoryax wants to merge 1 commit intowebpack:mainfrom
shoryax:fix/tree-shaking-unused-default-export
Open

fix: tree-shake unused default export in dynamic-reexport mode#20557
shoryax wants to merge 1 commit intowebpack:mainfrom
shoryax:fix/tree-shaking-unused-default-export

Conversation

@shoryax
Copy link

@shoryax shoryax commented Feb 28, 2026

this fixes the issue #20537, i:e,

when vue-loader generates an intermediary file that does export * from "./module", webpack falls into dynamic-reexport mode because it can't statically determine all exports. In this mode, it was returning EXPORTS_OBJECT_REFERENCED — marking ALL exports as used, including default.
But export * never re-exports default per the ES spec. The code already had mode.ignored which contains "default", but getReferencedExports wasn't checking it in the dynamic-reexport case.

What kind of change does this PR introduce?
Bug fix

Did you add tests for your changes?
Yes, added test/cases/optimize/tree-shaking-unused-default-export/

Does this PR introduce a breaking change?
Shouldn't be — this makes webpack correctly exclude default from export * re-exports, which is what the ES spec requires.

 Fix: in dynamic-reexport mode, iterate over known exports and skip any that are in mode.ignored, so 'default' is correctly excluded and can be tree-shaken.
Fixes: webpack#20537
@changeset-bot
Copy link

changeset-bot bot commented Feb 28, 2026

⚠️ No Changeset found

Latest commit: 73aa64d

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@linux-foundation-easycla
Copy link

CLA Not Signed

@alexander-akait
Copy link
Member

@shoryax What you fixed? Your code look like AI generated, describe changes in logic

@codspeed-hq
Copy link

codspeed-hq bot commented Feb 28, 2026

Merging this PR will degrade performance by 89.31%

⚡ 6 improved benchmarks
❌ 4 regressed benchmarks
✅ 134 untouched benchmarks

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

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Memory benchmark "asset-modules-inline", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' 731.9 KB 6,844.1 KB -89.31%
Memory benchmark "json-modules", scenario '{"name":"mode-development","mode":"development"}' 668.4 KB 541.7 KB +23.4%
Memory benchmark "asset-modules-resource", scenario '{"name":"mode-development","mode":"development"}' 3.2 MB 2 MB +56.79%
Memory benchmark "many-modules-esm", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' 298.9 KB 800.9 KB -62.68%
Memory benchmark "many-modules-commonjs", scenario '{"name":"mode-production","mode":"production"}' 9.2 MB 7.4 MB +23.91%
Memory benchmark "many-chunks-esm", scenario '{"name":"mode-production","mode":"production"}' 9.2 MB 7.2 MB +27.73%
Memory benchmark "asset-modules-inline", scenario '{"name":"mode-development","mode":"development"}' 2.3 MB 3.6 MB -35.86%
Memory benchmark "many-modules-commonjs", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' 798 KB 393 KB ×2
Memory benchmark "many-modules-commonjs", scenario '{"name":"mode-development","mode":"development"}' 980.1 KB 1,293.4 KB -24.23%
Memory benchmark "asset-modules-resource", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' 6,845.3 KB 733.3 KB ×9.3

Comparing shoryax:fix/tree-shaking-unused-default-export (73aa64d) with main (a3d7839)

Open in CodSpeed

@hai-x
Copy link
Member

hai-x commented Mar 3, 2026

I can’t see the issue based on the test case, and I don’t think this is a valid change.

dynamic-reexport dependency, means that provided info of the imported module exports is null, so we can only determine those exports at runtime. So for getReferencedExports, it will always return Dependency.EXPORTS_OBJECT_REFERENCED;

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.

3 participants