You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" in Node v21.5.0 #2100
First of all ,I already looked at #1997 and most of other websites to solve the problem but I couldn't.This error is throwed when I try to use in Node v21.5.0.I realized that The problem is node version,when I updated Node version to v19.0.0 it works.Could you please update ts-node to work in new Node versions.
Best regards.
Reacted by Vincent Rubinetti, Mohamed Wael Khobalatte, 糊涂, Bernat Vadell, chengmingwang, 1874., mehmet ilhan, Veikko Suhonen, Fröhlich Mara, Erik Krogh Kristensen and 91 more
Getting same issue, but I have a working version that I solved this issue on, and now a new project on which it does not. It is something else and I cannot remember what it is. Will report back once I have debugged the issue.
NOTE: I have just found this does not seem to support imports !!!
Reacted by Preston Bourne
Reacted by KEVIN BLACK, alexmejicanos-mc, Iordanis Sapidis, Dushant Ashok Banpurkar, Dzmitry, alsonfu888, jl917, miaojinsing, forcia-matsushita, Aldo 006 and 49 more
First of all ,I already looked at #1997 and most of other websites to solve the problem but I couldn't.This error is throwed when I try to use in Node v21.5.0.I realized that The problem is node version,when I updated Node version to v19.0.0 it works.Could you please update ts-node to work in new Node versions.
Could you please provide a minimal example of what does not work and then we can try to figure out why !
This is not an ESM package. Try setting type to module in your package.json.
Reacted by Pooriya, kimminjae, Dushant Ashok Banpurkar, forcia-matsushita, EsunR, iron-cherep, Mike Lautensack, noah james , Oscar Castro, Maksym Kotsiuruba and 37 more
C:\Users\Nathaniel\test\Node.js\ts-node-example>npm start
> ts-node-example@0.0.1 start
> ts-node src/index.ts
TypeError: Unknown file extension ".ts" for C:\Users\Nathaniel\test\Node.js\ts-node-example\src\index.ts
at Object.getFileProtocolModuleFormat [as file:] (node:internal/modules/esm/get_format:160:9)
at defaultGetFormat (node:internal/modules/esm/get_format:203:36)
at defaultLoad (node:internal/modules/esm/load:143:22)
at async ModuleLoader.load (node:internal/modules/esm/loader:409:7)
at async ModuleLoader.moduleProvider (node:internal/modules/esm/loader:291:45)
at async link (node:internal/modules/esm/module_job:76:21) {
code: 'ERR_UNKNOWN_FILE_EXTENSION'
}
Reacted by Daniel Wilkowski, madhawa priyashantha, AscendingEagle, BigBig, Randolph Harrison, thelyaa, forcia-matsushita, gachi0, iron-cherep, Yaya Aladji AYA and 28 more
C:\Users\Nathaniel\test\Node.js\ts-node-example>npm run start:node
> ts-node-example@0.0.1 start:node
> node --loader ts-node/esm src/index.ts
(node:18508) ExperimentalWarning: `--experimental-loader` may be removed in the future; instead use `register()`:
--import 'data:text/javascript,import { register } from "node:module"; import { pathToFileURL } from "node:url"; register("ts-node/esm", pathToFileURL("./"));'
(Use `node --trace-warnings ...` to show where the warning was created)
ts-node
NOTE: I have just found this does not seem to support imports !!!
Reacted by Kevin Guertin, Hugo Burton, Lee, atl31, LeeSeongJinCa, Arjun Nayak, liyongfen, Balázs Orbán, Abhishek Das, WANGMING and 6 more
Reacted by Andrea Stella, Mohamed Apdifitah, Ali Elmorsy, Budi Arsana, ~Excalibur, Josiah Hamm, Sparsh Tandon, Li, Bai Wu, AndreVJ71, AliMeer and 3 more
Reacted by Lee, Abhishek Das, Bruno Farias, KenanSivroSe and Joshua Alpuerto
Reacted by mehmet ilhan, Victor S., Kirill Gavrilov, emersonh-xyz, danni.cool, Lee, Balázs Orbán, Abhishek Das, Bruno Farias, KenanSivroSe and 1 more
Reacted by Lee, Bruno Farias, KenanSivroSe and Joshua Alpuerto
First of all ,I already looked at #1997 and most of other websites to solve the problem but I couldn't.This error is throwed when I try to use in Node v21.5.0.I realized that The problem is node version,when I updated Node version to v19.0.0 it works.Could you please update ts-node to work in new Node versions.
Could you please provide a minimal example of what does not work and then we can try to figure out why !
First of all ,I already looked at #1997 and most of other websites to solve the problem but I couldn't.This error is throwed when I try to use in Node v21.5.0.I realized that The problem is node version,when I updated Node version to v19.0.0 it works.Could you please update ts-node to work in new Node versions.
Could you please provide a minimal example of what does not work and then we can try to figure out why !
@cibilex - Did you manage to add the two commits to a ts-node fork or did you just patch the diff's ?
If you used git I would love to know how ! On the other front I seem to remember GitHub giving diffs but it does not seem to have downloads for them anymore. Or did you just use a reference to the repo in package.json dependencies ?
Reacted by Eduarte Paiva de Oliveira, William Spada, Humayun Kabir, Sarat Chandra Balla, eosmick, iron-cherep, lin onetwo, tanliwei, sarva, 814351846 and 11 more
Reacted by Christoph Gysin, Simon Fischer, Jannes Höke, Baptiste Garcin, russell-miburn, Kamil Burzynski, Jérôme, ねこマン, Ken Tam, Hanrea and 128 more
Reacted by Artur Klesun, luoriwusheng-xia, akay64, rinsuki, mehmet ilhan, Jackson Hu, Ryan de Kwaadsteniet, wenxuan feng, Aryan, Matt Chad and 31 more
Reacted by Keenwon and Abhishek Das
Reacted by Jaroslav Bereza, Roman Mahotskyi, Alexey Boklin, Adam, yuri, Rico, Sarat Chandra Balla, Alex I., eosmick, Abhishek Das and 2 more
I hope I found a way to handle that.
Don't worry it works well so kindly give a like if it solve your problem.
First, assure that in your package.json file, the type is set to module.
"type": "module"
Use the following configuration for in your tsconfig file :
The only way I've managed to get this to work is by setting the loader or import argument via NODE_OPTIONS. Don't bother trying with ts-node-esm or ts-node --esm, it's too late by that point.
Make sure your package.json contains "type": "module".
Set "allowImportingTsExtensions": true in your tsconfig.json.
Finally, you can can execute your TypeScript file like so: NODE_OPTIONS="--loader=ts-node/esm" npm exec ts-node index.ts
The --import method is almost the same. Just create a file containing the registration script:
In my case, on Node 22, there's no need for --loader.
I use --experimental-strip-types, but got this same error.
The solution was to make sure the CLI flag comes before the file to run.
Works:
node --experimental-strip-types ./src
Doesn't work:
node ./src --experimental-strip-types
Reacted by Johan Cornelissen, Sebastian Thomschke, Moritz Stückler and Anshul
I found a simpler way to run a TypeScript project with auto-reloading:
Install dev dependencies:
npm install --save-dev ts-node nodemon typescript
2. Initialize TypeScript to generate a tsconfig.json:
npx tsc --init
3. Add the following scripts to your package.json:
"scripts": {
"start": "ts-node index.ts",
"start:watch": "nodemon index.ts",
"build": "tsc"
}
4. Run the project in watch mode:
npm run start:watch
Activity
AaronNGray commentedon Jan 15, 2024
Getting same issue, but I have a working version that I solved this issue on, and now a new project on which it does not. It is something else and I cannot remember what it is. Will report back once I have debugged the issue.
AaronNGray commentedon Jan 16, 2024
Heres a working example with node v21.5.0, typescript v5.3.3, ts-node v10.9.2 :-
https://github.com/AaronNGray/ts-node-example
NOTE: I have just found this does not seem to support imports !!!
AaronNGray commentedon Jan 16, 2024
Could you please provide a minimal example of what does not work and then we can try to figure out why !
peschee commentedon Jan 16, 2024
This is not an ESM package. Try setting type to module in your package.json.
AaronNGray commentedon Jan 16, 2024
AFAICS I am not sure ts-node supports ESM. Could you provide the example that works on node v19.0.0, but not v21.5.0. Or is it as simple as setting
"type":"module"? As in :-https://github.com/AaronNGray/ts-node-example/tree/ts-node-esm-module
on v21.5.0 resulting in :-
AaronNGray commentedon Jan 16, 2024
Adding :-
"start:node": "node --loader ts-node/esm src/index.ts"and tsconfig.json :-
"module": "esnext"We have :-
https://github.com/AaronNGray/ts-node-example/tree/ts-node-esm-loader
which gives :-
NOTE: I have just found this does not seem to support imports !!!
cibilex commentedon Jan 16, 2024
I've modified the project a bit and created new repository.link: https://github.com/cibilex/ts-node-err
This project doesn't work in node v21.5.0 while works In node v16.20.2 for me.
AaronNGray commentedon Jan 16, 2024
You modified start to : -
"start": "ts-node-esm src/index.ts"The version I posted last works AFAICT without proper testing, but I did do an
importNote:
--loadermaybe deprecated.https://github.com/AaronNGray/ts-node-example/tree/ts-node-esm-loader
NOTE: I have just found this does not seem to support imports !!!
AaronNGray commentedon Jan 16, 2024
@cibilex - Theres a pull request waiting :- #2073
cibilex commentedon Jan 17, 2024
Thank you a lot,It works now splendid :)
AaronNGray commentedon Jan 17, 2024
@cibilex - Did you manage to add the two commits to a ts-node fork or did you just patch the diff's ?
If you used git I would love to know how ! On the other front I seem to remember GitHub giving diffs but it does not seem to have downloads for them anymore. Or did you just use a reference to the repo in package.json dependencies ?
cj-christoph-gysin commentedon Jan 18, 2024
You can just add
.diffor.patchto any github url for a commit or PR, e.g.: https://github.com/TypeStrong/ts-node/pull/2073.diffAaronNGray commentedon Jan 18, 2024
@cibilex - Wow great thanks, think I was over complicating things :)
MickL commentedon Feb 14, 2024
Guys no need for
ts-node, just use Deno or Bun:russell-miburn commentedon Feb 19, 2024
Is there an update on the progress of this bug?
53 remaining items
heyjunpenn commentedon Nov 11, 2024
Node version 18.17.0 where ts-node with package.json "type"="module" work fine
francip commentedon Nov 22, 2024
@SoMeu yes, because the version that broke it is v18.19.0.
feature: migrate to tsx from ts-node
hassamulhaq commentedon Dec 7, 2024
I was getting the same issue 'ERR_UNKNOWN_FILE_EXTENSION', and after two hours of investigation, I fixed it.
How to fix [nodemon] app crashed error and unknown file extension issues?
Note: i setup a fresh project using
npm create vite@latestand then chose 'Vanillas -> TypeScript' options.my old node version was 20.18.0
requirements
update nodejs version in ubuntu
create a
nodemod.jsonfile at root{ "watch": ["src"], "ext": "ts,json", "ignore": ["node_modules"], "exec": "node --loader ts-node/esm --experimental-specifier-resolution=node src/index.ts", "legacyWatch": true }update
package.jsonfilecreate a file
index.tsin src/ dirnow run nodemon dev server
my full
package.jsonfile{ "name": "nodejs-crud-app", "private": true, "version": "0.0.0", "type": "module", "scripts": { "dev": "vite", "build": "tsc && vite build", "preview": "vite preview", "dev:server": "nodemon" }, "devDependencies": { "nodemon": "^3.1.7", #[npm install --save-dev nodemon ts-node] "ts-node": "^10.9.2", "tsconfig-paths": "^4.2.0", "typescript": "~5.6.2", "vite": "^6.0.1" }, "dependencies": { "@types/express": "^5.0.0", #[npm i @types/express] "@types/node": "^22.10.1", #[npm i @types/node] "cors": "^2.8.5", #[npm i cors] "dotenv": "^16.4.7", #[npm i dotenv] "express": "^4.21.2", #[npm i express] "joi": "^17.13.3", "pg": "^8.13.1" } }extra
npm install ts-node tsconfig-paths sudo npm cache clean -f #[clean npm cache]hicodingx commentedon Dec 21, 2024
I hope I found a way to handle that.
Don't worry it works well so kindly give a like if it solve your problem.
First, assure that in your package.json file, the type is set to module.
Use the following configuration for in your tsconfig file :
{ "compilerOptions": { "skipLibCheck": true, "module": "ESNext", "moduleResolution": "bundler", "target": "ESNext", "isolatedModules": true, "esModuleInterop": true, "noEmit": true, "allowImportingTsExtensions": true, "outDir": "dist", "lib": ["esnext"], "types": ["node"], "baseUrl": "./" }, "exclude": ["node_modules"], "include": ["src/**/*.ts", "bin/*.ts"] }Use this in your package.json to start the dev server :
Finally, be sure that you didn't forget to add file extension when making an import.
vbudovski commentedon Dec 23, 2024
The only way I've managed to get this to work is by setting the
loaderorimportargument viaNODE_OPTIONS. Don't bother trying withts-node-esmorts-node --esm, it's too late by that point.package.jsoncontains"type": "module"."allowImportingTsExtensions": truein yourtsconfig.json.NODE_OPTIONS="--loader=ts-node/esm" npm exec ts-node index.ts--importmethod is almost the same. Just create a file containing the registration script:Then call it like so:
NODE_OPTIONS="--import ./ts-node.register.mjs" npm exec ts-node index.tssoryy708 commentedon Dec 29, 2024
In my case, on Node 22, there's no need for
--loader.I use
--experimental-strip-types, but got this same error.The solution was to make sure the CLI flag comes before the file to run.
Works:
Doesn't work:
programmingwithsalim commentedon Dec 30, 2024
npm i -D tsx
npx tsx src/index.ts
This worked for me
LucasGarcez commentedon Jan 2, 2025
I just created an empty
tsconfig.jsonfile in the root folder and started to work. Nothing else.It's an example project to run TS, so I only have
typescriptas a dependency.{ "dependencies": { "typescript": "^5.7.2" } }If it doesn't work for you, move on and use
tsxIt's also recommended in the Node.js docs: https://nodejs.org/en/learn/typescript/run#running-typescript-code-with-tsxheroku-postgres-wrong8 commentedon Feb 9, 2025
@AaronNGray Fvh5ndurCipw
yohanistadese commentedon Feb 9, 2025
Here is completely work.
1, First install this.
npm install -D tsx// install as development model2, After completely install:
3, finally work correctly run
npm run devNote-> watch mode is used for automatically start your typescript application when something change in you code.
Try to fix new typescript packaging issue
DonnerFranzel55 commentedon May 31, 2025
I found a simpler way to run a TypeScript project with auto-reloading:
tsconfig.json:package.json:reaishijie commentedon Sep 10, 2025
what's your package.json and tsconfig.json?
DonnerFranzel55 commentedon Sep 11, 2025
This is how a package.json could look like:
{ "name": "nodemon-with-ts", "version": "1.0.0", "description": "", "license": "ISC", "author": "", "type": "commonjs", "main": "index.ts", "scripts": { "start": "nodemon" }, "devDependencies": { "nodemon": "^3.1.10", "ts-node": "^10.9.2", "typescript": "^5.9.2" } }and the tsconfig.json is the default generated from: