Repository navigation
Regression in 5.112.0: Self-reference dependency has unused export name for CommonJS modules #22788
Description
Have you used AI?
Yes
Which part of webpack is affected?
not sure
Bug Description
Since webpack 5.112.0, production builds crash during bundle generation when side-effect-free CommonJS modules read their own exports inside functions. This is the same internal error as #21619. That issue's reproduction still builds on 5.112.0, but this package graph fails on 5.112.0 and builds on 5.111.1.
The error occurs with production usedExports optimization:
Self-reference dependency has unused export name: This should not happen
The failure was found in an application that reaches viem's CommonJS build through wagmi / @safe-global/safe-apps-sdk. The reproduction reduces this to a single require('viem').
Link to Minimal Reproduction and steps to reproduce
https://stackblitz.com/edit/webpack-self-reference-repro-1cmzhfxh?file=README.md
Steps:
- Run
pnpm install. - Run
pnpm run build. - See 8 errors from
@noble/curves,@scure/base,@scure/bip32andox/_cjs.
Optionally, run pnpm run build:without-tree-shaking and see how it succeeds. Pinning webpack to 5.111.1 also succeeds.
Expected Behavior
Webpack should tree-shake or retain the self-referenced exports and complete the build, as it does on 5.111.1.
Actual Behavior
Webpack aborts during bundle generation:
ERROR in ./node_modules/.pnpm/@noble+curves@1.9.7/node_modules/@noble/curves/abstract/hash-to-curve.js
Self-reference dependency has unused export name: This should not happen
ERROR in ./node_modules/.pnpm/@noble+curves@1.9.7/node_modules/@noble/curves/abstract/weierstrass.js
ERROR in ./node_modules/.pnpm/@noble+curves@1.9.7/node_modules/@noble/curves/secp256k1.js
ERROR in ./node_modules/.pnpm/@scure+base@1.2.6/node_modules/@scure/base/lib/index.js
ERROR in ./node_modules/.pnpm/@scure+bip32@1.7.0/node_modules/@scure/bip32/lib/index.js
ERROR in ./node_modules/.pnpm/ox@0.14.56/node_modules/ox/_cjs/core/Secp256k1.js
ERROR in ./node_modules/.pnpm/ox@0.14.56/node_modules/ox/_cjs/erc6492/SignatureErc6492.js
ERROR in ./node_modules/.pnpm/ox@0.14.56/node_modules/ox/_cjs/erc8010/SignatureErc8010.js
webpack 5.112.0 compiled with 8 errors
Running pnpm run build:without-tree-shaking succeeds.
Environment
System:
OS: macOS 26.7.1
CPU: (10) arm64 Apple M1 Max
Memory: 32.00 GB
Binaries:
Node: 22.22.2
pnpm: 10.33.0
Packages:
webpack: 5.112.0 => 5.112.0
webpack-cli: 6.0.1 => 6.0.1
viem: 2.57.7 (ox 0.14.56, @noble/curves 1.9.7)Is this a regression?
Yes (please specify version below)
Last Working Version
5.111.1
Additional Context
| Setup | Result |
|---|---|
| webpack 5.111.1 | Builds |
| webpack 5.112.0 | Fails |
webpack 5.112.0 with optimization.usedExports: false |
Builds |
| #21619 reproduction on webpack 5.112.0 | Builds |
Requiring @noble/curves/secp256k1 directly does not trigger the error. It only appears when these modules are reached through the viem → ox CommonJS graph, so I have not yet reduced it to plain source files.
Likely related to #21619, #13983 and #18315. This case does not use workers or usedExports: "global".
AI assistance was used to organize this report. I reviewed the reproduction, commands, and technical details.
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Effort
Activity
fix(cjs): flag exports used through a CommonJS namespace re-export
fix(cjs): flag exports used through a CommonJS namespace re-export (w…
chore(deps-dev): Nx 22.7.12 -> 23.3.0 via nx migrate