Skip to content

Regression in 5.112.0: Self-reference dependency has unused export name for CommonJS modules #22788

Closed

Description

@simrankaurmann

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:

  1. Run pnpm install.
  2. Run pnpm run build.
  3. See 8 errors from @noble/curves, @scure/base, @scure/bip32 and ox/_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.

Activity

  1. added
    area: optimizationTree-shaking, splitChunks, concatenation, ids (lib/optimize, lib/ids)
    area: parserJavaScript parsing and dependency analysis (lib/javascript, lib/dependencies)
    regressionWorked in a previous release; pair with the Affected version field
    on Oct 19, 2026
  2. added a commit that references this issue on Oct 19, 2026
    0ca9ae2
  3. added a commit that references this issue on Oct 19, 2026
    b90cb59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: optimizationTree-shaking, splitChunks, concatenation, ids (lib/optimize, lib/ids)area: parserJavaScript parsing and dependency analysis (lib/javascript, lib/dependencies)regressionWorked in a previous release; pair with the Affected version field

    Type

    Fields

    Priority

    None yet

    Effort

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions