-
-
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 *.mts file and --experimental-strip-types flag #6595
Comments
Hey @blutorange, can you please see if running |
@RDIL It didn't, but I saw your commit c38fd4e and noticed that the change wasn't applied to So yes, that commit should be enough to fix it. It's probably best to also add .cts for commonjs |
Whoops, I forgot to rebuild the loader, my bad. Will also add CTS! |
@RDIL adding
to pnp loader fixes the issue, can you merge your PR? Thanks |
Self-service
Describe the bug
Trying to run a
*.mt
file viayarn node
with notype
ortype: "commonjs"
in thepackage.json
fails and results in anERR_REQUIRE_ESM
error.:Judging from the error message
require() of ES Module
and.pnp.cjs
. I'm guessing yarn currently just doesn't implement the logic for treating*.mts
files as ESM and uses its.pnp.cjs
instead of.pnp.loader.mjs
?To reproduce
Make sure the
package.json
either has notype
or"type": "commonjs"
.Create two files:
Then run
yarn node --experimental-strip-types a.mts
. This will fail with an errorERR_REQUIRE_ESM'
Running
node --experimental-strip-types a.mts
works and printsWorld
.Environment
System: OS: Linux 6.8 Ubuntu 24.04.1 LTS 24.04.1 LTS (Noble Numbat) CPU: (8) x64 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz Binaries: Node: 22.11.0 - /tmp/xfs-ca62210f/node Yarn: 4.5.1 - /tmp/xfs-ca62210f/yarn npm: 10.9.0 - ~/.nvm/versions/node/v22.11.0/bin/npm
Additional context
Perhaps related to #6336 ?
The text was updated successfully, but these errors were encountered: