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
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
usingts-node/esm
and the latest node implementation of--require
rather than--loader
.node_modules
Actual Behavior
Error below
Steps to reproduce the problem
Minimal reproduction
Minimal reproduction repository; https://github.com/darcyrush/ts-node-test-err-require-esm
Specifications