ts-node: ERR_UNKNOWN_FILE_EXTENSION since Node.js 18.19.0 (works fine with 18.18.2)
Search Terms
- ERR_UNKNOWN_FILE_EXTENSION
- Node.js 18.19.0
- Node.js 18.18.2
Expected Behavior
npx ts-node <script.ts>
works on Node.js 18.19.0
just as it does with 18.18.2
.
Actual Behavior
Since the upgrade to Node.js 18.19.0
, the call fails with ERR_UNKNOWN_FILE_EXTENSION
.
All other potentially related parameters remained unchanged (e.g. package-lock.json
, ts-config.json
, etc.).
We discovered this with GitHub workflow runs that run periodically (with schedule
) at short intervals; only difference since things started failing is the Node.js version.
Steps to reproduce the problem
- set up Node.js 18.19.2
- set
"type": "module"
inpackage.json
- set
"esm": true
intsconfig.json
- create
main.ts
with something like:console.log('Hello world')
- run
npx ts-node main.ts
Minimal reproduction
see https://github.com/mlenkeit/ts-node-repro
there’s also a GitHub workflow to run this repo against Node.js 18.19.0
and 18.18.2
:
https://github.com/mlenkeit/ts-node-repro/actions/runs/7057725777
Specifications
- ts-node version: v10.9.1
- node version: v18.19.0
- TypeScript version: v5.2.2
- tsconfig.json, if you’re using one:
{ "extends": "@tsconfig/node18/tsconfig.json", "ts-node": { "esm": true }, "compilerOptions": { "allowSyntheticDefaultImports": true, "moduleResolution": "Node", "module": "ESNext", "noImplicitAny": false, "strictNullChecks": true, "sourceMap": true, "outDir": "./dist", "resolveJsonModule": false, "types": [ "node" ] }, "exclude": ["node_modules"] }
- package.json:
{ "name": "ts-node-repro", "private": true, "version": "1.0.0", "description": "", "main": "index.js", "type": "module", "dependencies": { "@tsconfig/node18": "18.2.2", "@types/node": "18.16.1", "ts-node": "10.9.1", "typescript": "5.2.2" } }
- Operating system and version: macOS Sonoma 14.1.1
About this issue
- Original URL
- State: open
- Created 7 months ago
- Reactions: 63
- Comments: 17
Commits related to this issue
- ci: use node v18.18.2 instead of v18.x Node v18.19.0 breaks `ts-node-esm`, so `pnpm install` won't work. See: https://github.com/TypeStrong/ts-node/issues/2094 — committed to aloisklink/mermaid by aloisklink 7 months ago
- chore: Workaround for build command by using node instead of ts-node See https://github.com/TypeStrong/ts-node/issues/2094 — committed to serlo/api.serlo.org by kulla 7 months ago
- build: use node 18.18.2 on requestor to mitigate ts-node issue https://github.com/TypeStrong/ts-node/issues/2094 — committed to golemfactory/golem-js by grisha87 7 months ago
- chore: Pin node version in docker base images and bump nvmrc (#3537) We were using a floating version of node in our base images, which means we didn't control when we updated the node version. Also... — committed to AztecProtocol/aztec-packages by spalladino 7 months ago
- chore: Pin node version in docker base images and bump nvmrc (#3537) We were using a floating version of node in our base images, which means we didn't control when we updated the node version. Also... — committed to AztecProtocol/barretenberg by spalladino 7 months ago
- ci: fix ts-node scripts (#5225) - Ref: https://github.com/TypeStrong/ts-node/issues/2094 — committed to toeverything/AFFiNE by Brooooooklyn 7 months ago
- Pin node version in scripts to 18.18 There is issue with node 18.19 and also newer version breaking ts-node: https://github.com/TypeStrong/ts-node/issues/2094. This is a quick fix until finding a mor... — committed to p2004a/maps-metadata by p2004a 7 months ago
- Pin node version in scripts to 18.18 (#232) There is issue with node 18.19 and also newer version breaking ts-node: https://github.com/TypeStrong/ts-node/issues/2094. This is a quick fix until find... — committed to beyond-all-reason/maps-metadata by p2004a 7 months ago
- CI (temp): fix typescript test runner failure due to ts-node bug This fix triggers some warnings about experimental features, and it's meant to be temporary until ts-node shares a long-term solutio .... — committed to openpgpjs/openpgpjs by larabr 7 months ago
- CI (temp): fix typescript test runner failure due to ts-node bug This fix triggers some warnings about experimental features, and it's meant to be temporary until ts-node shares a long-term solutio .... — committed to ProtonMail/openpgpjs by larabr 7 months ago
- pin nodejs to v18.18.2 see TypeStrong/ts-node#2094 — committed to k-yle/akl-ferry-capacity by k-yle 7 months ago
- fix: gh actions use node v18.18.2 TypeStrong/ts-node/issues/1997 TypeStrong/ts-node/issues/2094 — committed to hoonoh/ts-pg-model by hoonoh 7 months ago
- fix(deps): update dependency ts-morph to v21 (#199) * fix(deps): update dependency ts-morph to v21 * fix: gh actions use node v18.18.2 TypeStrong/ts-node/issues/1997 TypeStrong/ts-node/issues/2094 ... — committed to hoonoh/ts-pg-model by renovate[bot] 7 months ago
- hotfix: force node version to avoid buggy last one Check : https://github.com/TypeStrong/ts-node/issues/1997 https://github.com/TypeStrong/ts-node/issues/2094 — committed to betagouv/aides-jeunes by baptou12 7 months ago
- hotfix: force node version to avoid buggy last one Check : https://github.com/TypeStrong/ts-node/issues/1997 https://github.com/TypeStrong/ts-node/issues/2094 — committed to betagouv/aides-jeunes by baptou12 7 months ago
- hotfix: force node version to avoid buggy last one Check : https://github.com/TypeStrong/ts-node/issues/1997 https://github.com/TypeStrong/ts-node/issues/2094 — committed to betagouv/aides-jeunes by baptou12 7 months ago
- adapt to the breaking changes in Node.js 18.19 Refs: https://github.com/TypeStrong/ts-node/issues/2094 — committed to mmomtchev/sqlite-wasm-http by mmomtchev 7 months ago
- hotfix: force node version to avoid buggy last one (#4108) Check : https://github.com/TypeStrong/ts-node/issues/1997 https://github.com/TypeStrong/ts-node/issues/2094 — committed to betagouv/aides-jeunes by baptou12 7 months ago
- Fix TypeStrong/ts-node#2094 by using node --loader — committed to david-loe/abrechnung by david-loe 7 months ago
- chore: Fix call of ts-node See https://github.com/TypeStrong/ts-node/issues/2094 — committed to serlo/serlo-editor-for-edusharing by kulla 7 months ago
Workaround: You can use
node --loader ts-node/esm file.ts
instead ofts-node --esm file.ts
(which causes aExperimentalWarning: --experimental-loader may be removed in the future
). It would be great ifts-node
provided an entrypoint that callsregister
fromnode:module
, which seems to be Node’s preferred way of registering loaders, now.Same issue in node
v20.10.0
(current LTS)@michael42 thanks for the suggestion. This indeed works with both Node.js
18.18.2
and18.19.0
.I will, however, hold back with applying that change for now, as this would require changes across a dozen or so repos. We’ve simply pinned Node.js to
18.18.2
for now to unblock us.I still consider this to be a bug in
ts-node
.Any update on this? This has rendered ts-node completely unusable and not fit for purpose. The
node --loader ts-node/esm file.ts
and similar workarounds do not always work, and break all existing projects that now have to temporarily implement the workaround while this gets fixed.I agree that #1997 and this one probably share the same root cause.
Yet, I think they differ in their implication: If
ts-node
changed the way it works on a major version bump of Node.js, I’d say that’s acceptable. But ifts-node
suddenly stopped working on a minor version bump of Node.js, I’d say it’s a bug.This does not seem to work for me:
node --loader ts-node/esm -r tsconfig-paths/register ./scripts/deploy.ts
node --loader ts-node/esm index.ts
works for me@rreeves8 it works on Node.js 18.18.2. To my knowledge, any newer version runs into the problem described here (incl. Node.js 20). For following this kind of problem for Node.js 20, you may want to take a look at #1997 as well.
I’m using tsx with AWS CDK until this is resolved.
In cdk.json, change the app property to:
See #1997 - this sounds like a duplicate of that one.