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
$ cat example.tsconsole.log('example')
$ cat tsconfig.json{ "ts-node": { "esm": true } }
$ npx ts-node example.tsTypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for /Users/septs/Projects/example/example.ts at new NodeError (node:internal/errors:399:5) at Object.getFileProtocolModuleFormat [as file:] (node:internal/modules/esm/get_format:99:9) at defaultGetFormat (node:internal/modules/esm/get_format:139:38) at defaultLoad (node:internal/modules/esm/load:83:20) at nextLoad (node:internal/modules/esm/hooks:781:28) at load (/Users/septs/.npm/_npx/1bf7c3c15bf47d04/node_modules/ts-node/dist/child/child-loader.js:19:122) at nextLoad (node:internal/modules/esm/hooks:781:28) at Hooks.load (node:internal/modules/esm/hooks:381:26) at handleMessage (node:internal/modules/esm/worker:153:24) at checkForMessages (node:internal/modules/esm/worker:102:28) { code: 'ERR_UNKNOWN_FILE_EXTENSION'}
Reacted by Andrew Morris, liujiaqi222, Samuel Melkovič, Scott Dickerson, Seiry Yu, Maksim Meshkov, Joakim Bjerknes, Lulliezy, Radovan Janjic, n年级 and 10 more
Reacted by Nick Pomfret, Chris Savvopoulos, drilens, , Julien Viatgé, Martin Ševčík, Md Kawsar Islam Yeasin, Edy, Michael Bull, _Kerman and 17 more
I have the same issue. I tried using --esm, { "esm": true } and --loader="ts-node/register", but got the ERR_UNKNOWN_FILE_EXTENSION no matter what I tried. Could not get ts-node to run on Node v20 with native ESM modules.
Reacted by Jeff Wainwright, Petr Plenkov, Scott Willeke, James MARTIN, Steve Kehlet, Chris, John Smart, A-yon Lee, Steve, Alex and 83 more
Custom ESM loader hooks run on dedicated thread
ESM hooks supplied via loaders (--experimental-loader=foo.mjs) now run in a dedicated thread, isolated from the main thread. This provides a separate scope for loaders and ensures no cross-contamination between loaders and application code.
Reacted by septs, Giorgos Topsis, Juan C. Castellanos H., Yan Zhabin, Zbigniew Zagórski, Jeff Wainwright, waiting, drilens, Neelansh Mathur, Yun Shan and 18 more
Reacted by Tushar Sharma and Timothy Baumgartner
Reacted by Yan Zhabin, Ari Gibson, Funtik26, Dan Dascalescu, waiting, Changsheng Wu, Jinseok Seo (Jason Jin), Matt Zukowski, O-drey, Rich Evans and 9 more
I went forward and downgraded my node version to lts.
However, doing node --loader ts-node/esm {file} did work for me.
Reacted by Sepehr Samavati, nilscox, Maxime Golfier, Eduard Aksamitov, BellCube, Juntai Park, waiting, Ryosuke Iwanaga, Constantino Mamani, Nahoc and 88 more
Reacted by zzzgit, Alessandro Raffa, Murat Colyaran, Md Nazrul Islam, Ryan de Kwaadsteniet, Tran Quang Tien, Ricardo Sousa, Dirk Luijk, Emerson, mrgulc and 3 more
Reacted by BellCube, Juntai Park, Ryosuke Iwanaga, Hristina Kitanovska, Anaet Hossain Rezve, David Enke, lodeme, Changsheng Wu, Jayesh Patel, Joel Meiller and 21 more
i expirience the same issue on: Node v20,
I tried: $ node --loader ts-node/esm ./path
It worked for me but getting this warnning: ExperimentalWarning: Custom ESM Loaders is an experimental feature and might change at any time
Reacted by Sepehr Samavati, Mati Kärner, Matheus Sampaio Queiroga, Neelansh Mathur, Di, Changsheng Wu, aquinary, Yevhen Blotskyi, barinbritva, Erwin Gaitan and 26 more
I'd like to add quickly that on windows (at least), doing node --loader ts-node/esm ./path works but with an insanely high CPU usage. Doing a quick npx tsc + node ./build/app.js works perfectly without the performance issue.
Reacted by Anna Bocharova, Sepehr Samavati, waiting, Steve Kehlet, Jason , bluerose, Shen, UchihaYuki and khomyakov362
yeah, I recently upgraded to node 20 and started running with the --loader ts-node/esm parameter but noticed that my memory usage in my application had skyrocketed to 32G before it would die from OOM. I went chasing for a cause because I assumed it was due to a change I made, but downgrading to node 19 lowered memory usage down to around 500M again. I assume this is probably related to the CPU issues @sywesk had.
So I'd recommend people stay off Node 20 until this is fixed if you don't want to have unexpected issues in your runtime.
Reacted by Benjamin Bourgeais, Sepehr Samavati, septs, Amin Ya, waiting, Ronald J Kimball, John Smart, Andy, Stefan Löhers, Masoud G Sarini and 1 more
Reacted by Mathias Klippinge and Shaoyin Song
Reacted by Dan Dascalescu, waiting, Andy, Changsheng Wu and mango
@TopchetoEU tsx isn't a full replacement and doesn't have type checks, I'm a bit sceptical about their development model privatenumber/tsx#671 . Not even accepting contributions without a donation?
tsimp is great in theory, but it's extremely buggy, and can produce non-obviously stale results from because of caching bugs. tsc --noEmit && tsx is the way for now.
Reacted by arbassic, Art Furrer, Rich Evans and Benny Neugebauer
[webpack-cli] Unable load '/repo/folder/webpack.config.ts'
[webpack-clil Unable to use specified module loaders for " .ts".
[webpack-clil Cannot find module 'ts-node/register' from '/repo/folder'
[webpack-cli] Cannot find module 'sucrase/register/ts' from '/repo/folder'
[webpack-clil Cannot find module '@babel/register' from '/repo/folder'
[webpack-cli] Cannot find module 'esbuild-register/dist/node' from /repo/folder'
[webpack-clil Cannot find module '@swc/register' from '/repo/folder'
[webpack-clil Please install one of them
Webpack will check them in that order, mind you. So even if you have sucrase installed for example you have to manually uninstall ts-node before webpack automatically picks sucrase as loader.
So I just did (I use Yarn package manager, if you use NPM translate these commands to their equivalent)
yarn remove ts-node
and then
yarn add -D sucrase
No more configuration is needed (I don't have "type": "module" option in package.json, if you have it you may need additional configuration) and I can run webpack --config ./webpack.config.ts without any flags or workarounds.
Another thing, if you do not have "type": "module" option in package.json, the Webpack loader compiles the typescript config to commonJS, so you must use __dirname and __filename instead of import.meta.url if you need it, but you probably already know that.
ts-node is a great project and it has served me well over the years, so I'm sorry to have to remove it from my project. Please give all the support you can give to ts-node if you value it as I do.
Deno is still buggy... Bun too... Those nasty bugs are so annoying to find out later in the production..
Ironically with native ESM support in NodeJS, ts-node may start work again lol.
Reacted by TopchetoEU, Roberto Fuentes and christopher-stewart-slalom-snsc
Even though --experimental-specifier-resolution has been removed by nodejs it continues to work with ts-node because it appears to contain loader code copied from an older nodejs version (see the "ts-node/raw" dir) and this switch activates a code path that is capable of loading .ts files in ESM mode.
Reacted by Даниил Чистов, johnreybantoto, Clay Coleman, hdsuperman, MarcNum and razin786
Activity
septs commentedon Apr 20, 2023
microsoft/TypeScript#53922
Edited by 11/18/2023
Use tsx replace ts-node?
Or use ts-node@beta?
more see https://github.com/privatenumber/tsx, #2077
csvn commentedon Apr 20, 2023
I have the same issue. I tried using
--esm,{ "esm": true }and--loader="ts-node/register", but got theERR_UNKNOWN_FILE_EXTENSIONno matter what I tried. Could not getts-nodeto run on Node v20 with native ESM modules.Jack-Works commentedon Apr 21, 2023
FYI Node 20 has made a breaking change:
https://nodejs.org/en/blog/release/v20.0.0
RobinTail commentedon Apr 21, 2023
+1
The issue also appears when using the specially dedicated ESM runner
Disallow Node.js v20 for now
neurolag commentedon Apr 22, 2023
I went forward and downgraded my node version to
lts.However, doing
node --loader ts-node/esm {file}did work for me.wibed commentedon Apr 23, 2023
i expirience the same issue on:
# node --version v18.16.0EDIT:
my bad, i misinterpreted the gravity of the situation. manually enforcing the loader like this.
{ "start": "npm run clean && cross-env NODE_ENV=development NODE_OPTIONS=\"--loader=ts-node/esm --trace-warnings\" webpack serve --mode=development --config webpack.config.ts", }worked out.
example sourced from here:
webpack/webpack-cli#2458
RandivCosta commentedon Apr 29, 2023
i expirience the same issue on: Node v20,
I tried:
$ node --loader ts-node/esm ./pathIt worked for me but getting this warnning:
ExperimentalWarning: Custom ESM Loaders is an experimental feature and might change at any timesywesk commentedon May 4, 2023
I'd like to add quickly that on windows (at least), doing
node --loader ts-node/esm ./pathworks but with an insanely high CPU usage. Doing a quicknpx tsc+node ./build/app.jsworks perfectly without the performance issue.RobinTail commentedon May 6, 2023
Yes,
node --no-warnings=ExperimentalWarning --loader ts-node/esm file.tshelps to bypass the issue until it's fixed.Aenigma commentedon May 6, 2023
yeah, I recently upgraded to node 20 and started running with the
--loader ts-node/esmparameter but noticed that my memory usage in my application had skyrocketed to 32G before it would die from OOM. I went chasing for a cause because I assumed it was due to a change I made, but downgrading to node 19 lowered memory usage down to around 500M again. I assume this is probably related to the CPU issues @sywesk had.So I'd recommend people stay off Node 20 until this is fixed if you don't want to have unexpected issues in your runtime.
Node 20 changed enperimental loaders. Fix running tests on node 20
Run CI on node 20 rather than node 19
Fix for Node.js 20
feat: fix for Node 20 per TypeStrong/ts-node#1997
211 remaining items
TopchetoEU commentedon Oct 29, 2024
good point, but at least it still works with ESM.
ItsHarper commentedon Nov 1, 2024
tsimp is great in theory, but it's extremely buggy, and can produce non-obviously stale results from because of caching bugs.
tsc --noEmit && tsxis the way for now.the94air commentedon Nov 4, 2024
ts-watchseems not affected with these breaking changes in node 20. I haven't tested it with bigger projects yet.bennycode commentedon Nov 28, 2024
I created a video summarizing how to run
ts-nodewith ESM on Node 20+: https://www.youtube.com/watch?v=-7dNs1ggKRsThe
tsxtool is the recommended alternative (mentioned by @blakeembrey in #2140).imawizrd commentedon Nov 28, 2024
Showcase of the problem:
demo.mp4
Here's all the loaders webpack supports
Webpack will check them in that order, mind you. So even if you have
sucraseinstalled for example you have to manually uninstallts-nodebefore webpack automatically pickssucraseas loader.So I just did (I use Yarn package manager, if you use NPM translate these commands to their equivalent)
yarn remove ts-nodeand then
yarn add -D sucraseNo more configuration is needed (I don't have
"type": "module"option in package.json, if you have it you may need additional configuration) and I can runwebpack --config ./webpack.config.tswithout any flags or workarounds.Another thing, if you do not have
"type": "module"option in package.json, the Webpack loader compiles the typescript config to commonJS, so you must use__dirnameand__filenameinstead ofimport.meta.urlif you need it, but you probably already know that.ts-nodeis a great project and it has served me well over the years, so I'm sorry to have to remove it from my project. Please give all the support you can give to ts-node if you value it as I do.wes992 commentedon Dec 13, 2024
This worked for me. By far the best solution I have come across. :)
felipecrs commentedon Dec 13, 2024
Well, if there's anything positive out of it, I hope it somehow incentivize people to try a better runtime like Deno or Bun.
TopchetoEU commentedon Dec 13, 2024
unfortunately, sometimes you don't get to pick your runtime, and you're forced to use NodeJS, despite your best wishes.
dandv commentedon Dec 14, 2024
I've switched to Deno, but there are still some rough edges, especially when it comes to testing:
Also, there's no interop with ESLint rules, and Deno's built-in linting is just not up to par with typescript-eslint.
shinebayar-g commentedon Dec 14, 2024
Deno is still buggy... Bun too... Those nasty bugs are so annoying to find out later in the production..
Ironically with native ESM support in NodeJS, ts-node may start work again lol.
lexandera commentedon Jan 6, 2025
What has been working for me for a long time - and continues to work on node 22 - is the following:
node --experimental-specifier-resolution=node --loader ts-node/esm/transpile-only file.tsEven though
--experimental-specifier-resolutionhas been removed by nodejs it continues to work with ts-node because it appears to contain loader code copied from an older nodejs version (see the "ts-node/raw" dir) and this switch activates a code path that is capable of loading .ts files in ESM mode.gofugui commentedon May 21, 2025
package.json add "type": "module",
resistdesign commentedon Dec 23, 2025
Ok so TSX going forward then?
felipecrs commentedon Dec 23, 2025
If you don't need type checking, yeah. But nowadays even Node.js supports running most Typescript files.
neurolag commentedon Dec 23, 2025
this, or
vite-node: https://github.com/antfu-collective/vite-node