Self-service
Describe the bug
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".
Create two files:
// a.mts
import Message from "./b.mts";
console.log(Message);
// b.mts
const Hello = "World";
export default Hello;
Then run yarn node --experimental-strip-types a.mts. This will fail with an error ERR_REQUIRE_ESM'
Running node --experimental-strip-types a.mts works and prints World.
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 ?
Self-service
Describe the bug
Trying to run a
*.mtfile viayarn nodewith notypeortype: "commonjs"in thepackage.jsonfails and results in anERR_REQUIRE_ESMerror.:Judging from the error message
require() of ES Moduleand.pnp.cjs. I'm guessing yarn currently just doesn't implement the logic for treating*.mtsfiles as ESM and uses its.pnp.cjsinstead of.pnp.loader.mjs?To reproduce
Make sure the
package.jsoneither has notypeor"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.mtsworks 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/npmAdditional context
Perhaps related to #6336 ?