-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Description
Bug Description
An unused function in ESM code winds up being incorrectly transformed, referencing a global variable rather than the imported variable.
This causes an unrelated variable in the entry module that happens to have the same name to be renamed.
Link to Minimal Reproduction and step to reproduce
Reproduction: test.zip
- Unzip the reproduction project.
- Run
npm install && npm exec webpack. - Examine
dist/main.js.
Expected Behavior
If function unused() is not tree-shaken out, it looks something like this:
function unused() {
return (0,_i18n_js__WEBPACK_IMPORTED_MODULE_0__.__)( "wtf" );
}Also, in the entry module, the const __ retains that name.
Actual Behavior
Function unused() is present, but incorrectly appears like this:
function unused() {
return __( "wtf" );
}Also the const __ has been renamed to const src_, presumably to avoid interfering with that global variable reference.
Environment
System:
OS: Linux 6.16 Debian GNU/Linux forky/sid
CPU: (16) x64 AMD Ryzen 7 7840U w/ Radeon 780M Graphics
Memory: 22.74 GB / 30.66 GB
Binaries:
Node: 22.21.0 - /usr/bin/node
Yarn: 1.22.22 - /usr/local/bin/yarn
npm: 10.9.4 - /usr/bin/npm
pnpm: 10.23.0 - /usr/local/bin/pnpm
Browsers:
Firefox: 145.0.1
Firefox Developer Edition: 145.0.1
Packages:
webpack: 5.103.0 => 5.103.0
webpack-cli: ^6.0.1 => 6.0.1Is this a regression?
None
Last Working Version
No response
Additional Context
v5.92.0 introduced the "const __ has been renamed to const src_" part, presumably due #18772. Turning off optimization.avoidEntryIife works around that part.
Versions as far back as v5.61.0 generate the incorrect code in the unused function. I couldn't check earlier versions due to errors like "error:0308010C:digital envelope routines::unsupported".