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
When I try to execute a typescript file I get the following error message:
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for /home/$USERNAME/$PATH_TO_DEV_FOLEDER/index.ts
at Loader.defaultGetFormat [as _getFormat] (internal/modules/esm/get_format.js:65:15)
at Loader.getFormat (internal/modules/esm/loader.js:113:42)
at Loader.getModuleJob (internal/modules/esm/loader.js:243:31)
at Loader.import (internal/modules/esm/loader.js:177:17)
Steps to reproduce the problem
launch ts-node index.ts
Minimal reproduction
Specifications
ts-node version: v8.10.2 (installed global)
node version: v14.3.0
TypeScript version:v3.9.3 (installed global)
tsconfig.json, if you're using one:
{}
Operating system and version: Windows 10 Version 2004
If Windows, are you using WSL or WSL2?: Yes, Ubuntu 20.04 LTS in WSL2
Reacted by Juhan Oskar Hennoste, Wow, Dan G, Louis Birla, Adam Loving, Dan Dascalescu, Mateja Petrovic, Jamie Haywood, Avindra Goolcharan, Daniel Gustaw and 94 more
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for www\server\src\server.ts at Loader.defaultGetFormat [as _getFormat] (internal/modules/esm/get_format.js:65:15) at Loader.getFormat (internal/modules/esm/loader.js:113:42) at Loader.getModuleJob (internal/modules/esm/loader.js:243:31) at Loader.import (internal/modules/esm/loader.js:177:17)
Reacted by Caio Tony, SeniorMars, dil-gurumoorthy, Leonam Santos, Colin Goodale, Vincenzo Bianco, David P., Conner Bachmann, Dinesh Rawat, joakim and 2 more
Reacted by Dan Dascalescu, François, Oliver Lopez , SMJS, Tobias Berger, Igor Loskutov, Sergey, Victor Lechuga, Maxie, Zxilly and 108 more
Reacted by Marcos Loureiro, Erwann Lagouche, Igor Ribeiro, João Pedro, François Risoud, Donald KANTI, Tobias Weger and Maté Antunovic
On Sun, Jun 21, 2020, 9:44 AM AguinaldoAlberto ***@***.***> wrote:
Estou tendo o mesmo problema também
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for
www\server\src\server.ts at Loader.defaultGetFormat [as _getFormat]
(internal/modules/esm/get_format.js:65:15) at Loader.getFormat
(internal/modules/esm/loader.js:113:42) at Loader.getModuleJob
(internal/modules/esm/loader.js:243:31) at Loader.import
(internal/modules/esm/loader.js:177:17)
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#1062 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAC35OCO5M3WUUNXSLA4YS3RXYFCVANCNFSM4NOUHHYQ>
.
Reacted by Mak, Scott W, Aaron, Ron Don Jon, Daniel Niccoli, Jacob Linney, Matthew Schwartz, DoctorMcKay, kingasala, Javier Pérez and 85 more
Reacted by Peekayy, Scott Vachalek, Yaroslav Zotov, Błażej Bałtruszewicz, Micah Zoltu, Nathan, negue, Rick Zhou, HouPu, liam and 167 more
Reacted by panda2134, ilya-sv, Dan G, Johnson Okoro, Abhijeet Singh, gillminister, Oleg Kuzmenko, Mike, Mateja Petrovic, umudik and 660 more
Reacted by gtjman, Ícaro Motta, Stathis Charitos, Dusk, CamilleDU3, Vasily Mishanin, Hoàng Vũ Nhật Tân, fake js developer and Klarc Almeida
Reacted by Jelo, Vishal Solanki, Azamatzhon Akhunzhanov, Felix Orinda, Nicolas Went, Juan Brundi Sarmento Madeira, auragit, Ique Moraes, Omer Gery, Samuel Mitterrutzner and 7 more
Reacted by Aleksei Gorb, Steven Fowler, ilya-sv, Helcio Pandelo, Dan G, James Ward, andreea96, Tom Aylott, Dan Dascalescu, Mayra Cademartori and 53 more
Reacted by gtjman, instafiore, Ouardini Anas and Rody Huancas
Reacted by Yaroslav Zotov, negue, gk, Tobias Hochgürtel, Darvesh, Ryan Oboril, Kevin Wang, Leo Wang(草鞋没号), Renan Garcia Borges, Marcus Vinícius and 16 more
Reacted by Brian Kim, Darvesh, regard0606, IcyW, Vishal Solanki, Juan Brundi Sarmento Madeira, leCheng, GDur, Mario Kehne, gtjman and 4 more
If remove module type, you cannot use imports in your .ts files
Reacted by Eli, Dimitri Dumont, Mayra Cademartori, revozhang, Paweł Jankowski, Timmy Chan, Cody Ebberson, Crumb, Samuel David Hardy, Matúš Duchoň and 444 more
Reacted by remjx, Jussi Räsänen, Sergio S., Jan Grz, Gabriel Basilio, Ibad Ullah Shaikh, Ștefan-Gabriel Muscalu, Oliver Stigley, Antoni Kępiński, Nyan Helsing and 7 more
Reacted by Aurelian Spodarec
Reacted by A, MartynLCD3, Erwann Lagouche, co-dax, Erwann Bernier, adam, Nyan Helsing, john, Pol Peiffer, Javier Villatoro and 1 more
Reacted by IcyW, Surojit Ghosh, James McCarthy, nif, Erwann Lagouche, co-dax, 面向搜索引擎专家 and James Chen
I must disagree. In Angular projects, there is no "type": "module" in package.json and import synthax works fine. Try to set "module": "es2020" in tsconfig.json
Reacted by aspecs
Reacted by Mike, Ara Kazaryan, Samuel, Mihael Anđel, revozhang, Gene Levitzky, Reyad Attiyat, Anles, Daniel Gustaw, Matt Kenefick and 313 more
Reacted by Jack Bentsen
Reacted by Hardev, Matt DeBoard, PupoSDC, Dominik Reinert, A, Marek, Vũ Tiến Đạt, #, Matt Kenefick and Abdallah Alhabarneh
I must disagree. In Angular projects, there is no "type": "module" in package.json and import synthax works fine. Try to set "module": "es2020" in tsconfig.json
nope, same problem with import.
"Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension."
I created a template repo which can be used by anyone who has trouble initializing ts-node.
Reacted by Binbiubiubiu, Keith Carrillo, Macsik121, tetsu.k, Azeez Abass, Diyor Khaydarov, romaro, Brady Holt, Johnny Lee-Othon, Sina Pirani and 2 more
Reacted by Florian Tatzky, Steffen Schneider, KHENISSI Mehdi, Alex, sheraz-sarwar, A-J Roos, bitdom8, BrendonLapp, Renato Campos, Zachary Raineri and 53 more
Closing as this is not a ts-node bug. If you want to use node's native ESM support, which is currently experimental, then you can use ts-node's experimental ESM loader hook. See #1007 for details.
Reacted by Chaofeng Wang, Artiom Neganov, Landon, WB and Matt Wonlaw
Reacted by Steve Taylor, Sergey, samuelkdavis-mccarthyfinch, hersveit, Rafael da Rocha, Matthieu Garrigues, tarnishablec, Antonio Stoilkov, Eassame, fxmarty and 164 more
Reacted by Brian Kim, Brandon Duffany, Ara Kazaryan, Paul Morgan III, gillminister, Rebeca Borges, Crumb, Gene Levitzky, Avindra Goolcharan, Anles and 35 more
I got this same error (Unknown file extension ".ts"), trying to run a typescript script with ts-node 10.9.1 and Node 20.10. I couldn't find a solution unfortunately (I tried "esModuleInterop": true in tsconfig), but running the script through tsx worked, so I ended up migrating from ts-node to tsx.
I find it really odd that .ts files are not recognised by default. Surely ts-node should know how to handle .ts files?
Switching to tsx was the only thing that worked for me. Now it's as simple as yarn tsx . and BOOM. Not sure what the problem with ts-node is. It's defintely a ts-node problem.
Reacted by Raman Sinclair, Matthew Moore, Wiebe Zweers, Eldar, Gabriel Castillo and TjenWellens
Activity
[-]Error: unknown file extension.ts[/-]cspotcode commentedon Jun 2, 2020
ESM stuff? You might have better luck on our ESM thread. Or post a complete reproduction so someone else can debug.
ascochran commentedon Jun 6, 2020
I'm having the same issue.
Aguinaldo-Alberto-Naldo commentedon Jun 21, 2020
Estou tendo o mesmo problema também
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for www\server\src\server.ts at Loader.defaultGetFormat [as _getFormat] (internal/modules/esm/get_format.js:65:15) at Loader.getFormat (internal/modules/esm/loader.js:113:42) at Loader.getModuleJob (internal/modules/esm/loader.js:243:31) at Loader.import (internal/modules/esm/loader.js:177:17)cspotcode commentedon Jun 21, 2020
clinkadink commentedon Jun 28, 2020
Remove "type": "module" from package.json
SaintPhill commentedon Jul 16, 2020
If remove module type, you cannot use imports in your .ts files
Thomas1664 commentedon Jul 16, 2020
I must disagree. In Angular projects, there is no "type": "module" in package.json and import synthax works fine. Try to set "module": "es2020" in tsconfig.json
SaintPhill commentedon Jul 16, 2020
nope, same problem with import.
"Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension."
Thomas1664 commentedon Jul 17, 2020
I created a template repo which can be used by anyone who has trouble initializing
ts-node.cspotcode commentedon Jul 29, 2020
Closing as this is not a
ts-nodebug. If you want to use node's native ESM support, which is currently experimental, then you can usets-node's experimental ESM loader hook. See #1007 for details.paxperscientiam commentedon Dec 10, 2020
@clinkadink thanks, that did it for me
69 remaining items
fix(build): replace ts-node with tsx to resolve issues with modules (…
fix(build): replace ts-node with tsx to resolve issues with modules (…
hellznrg commentedon Jun 4, 2024
Switching to tsx was the only thing that worked for me. Now it's as simple as
yarn tsx .and BOOM. Not sure what the problem with ts-node is. It's defintely a ts-node problem.fix(build): replace ts-node with tsx to resolve issues with modules (s…
fix(build): replace ts-node with tsx to resolve issues with modules (…
fix(build): replace ts-node with tsx to resolve issues with modules (…
fix(build): replace ts-node with tsx to resolve issues with modules (…
fix(build): replace ts-node with tsx to resolve issues with modules (s…
fix(build): replace ts-node with tsx to resolve issues with modules (…
fix(build): replace ts-node with tsx to resolve issues with modules (…
fix(build): replace ts-node with tsx to resolve issues with modules (…
fix(build): replace ts-node with tsx to resolve issues with modules (…
fix(build): replace ts-node with tsx to resolve issues with modules (…
fix(build): replace ts-node with tsx to resolve issues with modules (…
fix(build): replace ts-node with tsx to resolve issues with modules (…