ERR_REQUIRE_ESM from esm.mjs
#1820
-
Hi! Node 16.15.1 Whenever I try to run ts-node, utilizing ESM, I get the following error:
It looks like it's triggering on the following lines from
I'm running the following command to call tsnode: My tsconfig: {
"ts-node": {
"experimentalResolver": true
},
"compilerOptions": {
"moduleResolution": "node",
"module": "esnext",
"target": "es6",
"lib": ["ESNext", "DOM"],
"allowJs": true,
"outDir": "./dist",
"sourceMap": true,
"resolveJsonModule": true,
"esModuleInterop": true,
"strict": false,
"strictNullChecks": false
},
"include": ["./src/**/*.ts", "./src/**/*.js"],
"exclude": ["./src/**/*.test.ts", "./dist", ".eslintrc.cjs"]
} I also have I've no idea what I'm doing wrong, or if it's actually a bug |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Aside from that, |
Beta Was this translation helpful? Give feedback.
node -r ts-node/esm
is the mistake. Our docs explain correct usage: https://typestrong.org/ts-node/docs/imports-r ts-node/esm
tells node to requirets-node/esm
which points tonode_modules/ts-node/esm.mjs
.esm.mjs
is an ESM module and cannot be required, which is why you get that error. It was a fair guess to thinkdist/esm
might be related, but in this case it is not.Aside from that,
ts-node/esm
is a node ESM loader so must be used with--loader
, not-r
.