Skip to content

require.context not parsed in ESM packages #15372

@tavoyne

Description

@tavoyne

Bug report

What is the current behavior?

In packages with type: "module", webpack fails to parse and replace require.context() expressions.

If the current behavior is a bug, please provide the steps to reproduce.

  1. Clone https://github.com/tavoyne/webpack-2ece8c.
  2. Run yarn webpack --mode=production.
  3. Inspect the dist/main.js file and notice that the require.context() expression is still present.
  4. (Remove type: "module" from the package.json file.)
  5. (Inspect the dist/main.js file again and notice how the require.context() expression was successfully replaced.)

What is the expected behavior?

The replacement to be successful at step (3).

As require is not available in ESM environments, it could be called import.context in order to avoid confusion.

Other relevant information:
webpack version: 5.68.0
Node.js version: 17.4.0
Operating System: MacOS
Additional tools: N/A

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions