[Error [ERR_REQUIRE_ESM]: require() of ES Module /.../node_modules/ts-node/esm.mjs not supported.
darcyrush opened this issue · 1 comments
darcyrush commented
Search Terms
ERR_REQUIRE_ESM
esm.mjs not supported.
[Error [ERR_REQUIRE_ESM]: require() of ES Module /.../node_modules/ts-node/esm.mjs not supported.
Expected Behavior
I am trying to run node
using ts-node/esm
and the latest node implementation of --require
rather than --loader
.
- Test should run and pass
- ESM error shouldn't point to a file within ts-node in
node_modules
Actual Behavior
Error below
> test
> TS_NODE_PROJECT=./test/tsconfig.json node --require ts-node/esm --test 'test/main.test.ts'
node:internal/modules/cjs/loader:1262
throw new ERR_REQUIRE_ESM(filename, true);
^
[Error [ERR_REQUIRE_ESM]: require() of ES Module /.../node_modules/ts-node/esm.mjs not supported.
Instead change the require of /.../node_modules/ts-node/esm.mjs to a dynamic import() which is available in all CommonJS modules.] {
code: 'ERR_REQUIRE_ESM'
}
Node.js v22.0.0
Steps to reproduce the problem
npm install
npm run test # Error
npm run build # To see that `tsc` compiles fine
Minimal reproduction
Minimal reproduction repository; https://github.com/darcyrush/ts-node-test-err-require-esm
Specifications
- ts-node version: v10.9.1
- node version: v22.0.0 (and 21, and 20 etc)
- TypeScript version: 5.4.5
- tsconfig.json: Find in linked repo; https://github.com/darcyrush/ts-node-test-err-require-esm/blob/main/test/tsconfig.json
- Operating system and version: Ubuntu 22.04 LTS, Kernel 5.15.0-105-generic
darcyrush commented
Cannot RTFM, --import
instead of --require
. I get the widely documented Unknown file extension
error