-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug?]: ERR_REQUIRE_ESM
in Yarn PnP mode using Node.js 22 with --experimental-require-module
flag
#6336
Comments
I need this as well |
I now have this patch, created on top of @yarnpkg/cli/4.5.0, which I'm using in my project and everything works so far. I copied some helpers from loader/node-options.js into nodeUtils.ts so that I can check if happy to submit this as a PR |
This flag is now enabled by default in node 23 so I guess this issue should be prioritised |
The related tests are failing in CITGM: nodejs/node#56040 (comment) - already failing in v23 for a couple of months, and will fail soon on v22.x too after v22.12.0 unflags require(esm), I suppose if it never gets fixed we should consider removing yarn from CITGM until it gets fixed to keep CITGM clean, since it's a known issue that doesn't affect most usage of yarn, but rather should be considered a bug in yarn when pnp + require(esm) is used, since the monkey patching code is supposed to match the default behavior, which now no longer throws on require(esm). Also IIUC the tests seem to be buggy as well? From #4024 they seem to be testing that ERR_REQUIRE_ESM is thrown by yarn when pnp is used, so should've been unaffected by what the default loading does. Yet it is, which means the tests are bypassing pnp which is what it tries to test. By the way you can do the feature detection using |
Self-service
Describe the bug
ERR_REQUIRE_ESM
when requiring an ES module from CommonJS using Yarn PnP with Node.js 22 with--experimental-require-module
flag.To reproduce
https://codesandbox.io/p/devbox/nervous-leavitt-ndnn53
Environment
Additional context
Would expect this to work, thanks to nodejs/node#51977.
Disabling Yarn PnP works: https://codesandbox.io/p/devbox/nervous-leavitt-forked-9mgdvt
The text was updated successfully, but these errors were encountered: