Skip to content

[ERR_REQUIRE_ESM]: require() of ES Module when using ES loader #15930

@wclr

Description

@wclr

Bug report

Trying to use a ESM module as a loader, simple repro:

https://github.com/wclr/webpack-esm-loader-issue

What is the current behavior?

Module build failed (from ./loader.js):
Error [ERR_REQUIRE_ESM]: require() of ES Module ..\webpack-esm-loader-issue\loader.js from D:\Code\webpack-esm-loader-issue\node_modules\loader-runner\lib\loadLoader.js not supported.
Instead change the require of loader.js in ..\webpack-esm-loader-issue\node_modules\loader-runner\lib\loadLoader.js to a dynamic import() which is available in all CommonJS modules.

Other relevant information:
webpack version: 5.73.0
Node.js version: 16
Operating System: Windows 10

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