not even the most simple use-case
AndreLeifert opened this issue · 3 comments
sudo npm i -g ts-node typescript
ts-node -v
v10.9.1
echo 'console.log("OK")' > tst.ts
ts-node tst.ts
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for /home/andre/play/tic/bmos-ic/tst.ts
at new NodeError (node:internal/errors:405:5)
at Object.getFileProtocolModuleFormat [as file:] (node:internal/modules/esm/get_format:79:11)
at defaultGetFormat (node:internal/modules/esm/get_format:124:36)
at defaultLoad (node:internal/modules/esm/load:84:20)
at nextLoad (node:internal/modules/esm/loader:163:28)
at ESMLoader.load (node:internal/modules/esm/loader:603:26)
at ESMLoader.moduleProvider (node:internal/modules/esm/loader:457:22)
at new ModuleJob (node:internal/modules/esm/module_job:64:26)
at ESMLoader.#createModuleJob (node:internal/modules/esm/loader:480:17)
at ESMLoader.getModuleJob (node:internal/modules/esm/loader:434:34) {
code: 'ERR_UNKNOWN_FILE_EXTENSION'
}
Adding to this, I can't get ts-node to work at all with ESM.
A brand new project with a package.json:
{
"type": "module",
"dependencies": {
"ts-node": "^10.9.1",
"typescript": "^5.2.2"
}
}
... and a tsconfig.json:
{
"type": "module",
"compilerOptions": {
"target": "ES2022",
"module": "ES2022"
},
"ts-node": {"esm": true}
}
Refuses to run script.ts
console.log("Hello world")
... with TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for <path>\project\script.ts
Very non-descriptive error message.
Yes, confirmed: like @Bjoren, I have "type": "module" in my package.json.
Also tried with --esm on the command line as well as with ts-node-esm... whatever that is.
Same result. Do we really have to add the suffix .js to all imports?