Skip to content

Strict-mode block function named require causes dependencies outside its block to be omitted #22797

Closed

Description

@CPunisher

Have you used AI?

Yes.

Which part of webpack is affected?

parser (JavaScript parsing, import/export analysis)

Bug Description

Webpack treats a block-scoped function named require as shadowing the outer CommonJS require, even in strict mode:

function load() {
  "use strict";
  {
    function require() {}
  }
  return require("./lib.js");
}

module.exports = load();

Link to Minimal Reproduction and steps to reproduce

StackBlitz reproduction

  1. Open the reproduction and let it install dependencies.
  2. Run npm start if it does not start automatically.
  3. Inspect the strict block function (repro) results and dist/index-webpack/bundle.cjs.

Expected Behavior

The function declaration is scoped to its block. Webpack should bundle lib.js and transform the subsequent require("./lib.js") call, preserving the original Node.js behavior.

Actual Behavior

The build succeeds, but lib.js is omitted and the require call remains untransformed, causing a runtime error without a host-provided require.

Environment

Collected using webpack info in the local reproduction environment:

System:
  OS: Linux 7.2 Arch Linux
  CPU: (16) x64 Intel(R) Core(TM) Ultra X9 388H
  Memory: 33.70 GB / 62.20 GB
Binaries:
  Node: 24.21.0
  npm: 11.19.0
  pnpm: 11.26.0
Packages:
  webpack: 5.112.0

Also reproduced in StackBlitz.

Is this a regression?

Unknown; previous versions have not been tested.

Last Working Version

Not identified.

Additional Context

The original source runs correctly in Node.js, and esbuild-wasm 0.28.2 bundles the dependency correctly.

AI assisted with preparing this report and reproduction. The reported behavior was verified by running the reproduction.

Activity

  1. added
    area: parserJavaScript parsing and dependency analysis (lib/javascript, lib/dependencies)
    on Oct 19, 2026
  2. added a commit that references this issue on Oct 19, 2026
    6966d15
  3. added a commit that references this issue on Oct 19, 2026
    d318c6c
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: parserJavaScript parsing and dependency analysis (lib/javascript, lib/dependencies)

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions