You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Trying to run a *.mt file via yarn node with no type or type: "commonjs" in the package.json fails and results in an ERR_REQUIRE_ESM error.:
node:internal/modules/cjs/loader:1314
throw new ERR_REQUIRE_ESM(filename, true);
^
Error [ERR_REQUIRE_ESM]: require() of ES Module /home/user/git/project/a.mts not supported.
at require$$0.Module._load (/home/user/git/project/.pnp.cjs:6014:31)
at TracingChannel.traceSync (node:diagnostics_channel:315:14) {
code: 'ERR_REQUIRE_ESM'
}
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 no type or "type": "commonjs".
@RDIL It didn't, but I saw your commit c38fd4e and noticed that the change wasn't applied to .pnp.loader.mjs, even after I deleted that file and had yarn recreate it. I manually added your change regarding getFileFormat to my local copy of .pnp.loader.mjs. Then it worked : ) Probably just an issue with installing from sources.
So yes, that commit should be enough to fix it. It's probably best to also add .cts for commonjs
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: