Load typescript files
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)
launch ts-node index.ts
{}
ESM stuff? You might have better luck on our ESM thread. Or post a complete reproduction so someone else can debug.
I'm having the same issue.
λ npx ts-node src/app.ts
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for C:\Users\$USER\$PATH_TO_DEV_FOLDER\src\app.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)
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)
My earlier suggestion should point you in the right direction.
On Sun, Jun 21, 2020, 9:44 AM AguinaldoAlberto notifications@github.com
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
https://github.com/TypeStrong/ts-node/issues/1062#issuecomment-647130364,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AAC35OCO5M3WUUNXSLA4YS3RXYFCVANCNFSM4NOUHHYQ
.
Remove "type": "module" from package.json
Remove "type": "module" from package.json
If remove module type, you cannot use imports in your .ts files
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
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.
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.
@clinkadink thanks, that did it for me
We've enabled the discussion forum for questions like this one.
https://github.com/TypeStrong/ts-node/discussions
We're trying to keep the issue tracker limited to actionable tasks, so contributors can focus on making fixes and improvements to ts-node.
Since this is not a bug and nothing needs to change in ts-node, it's not actionable, so it was closed. Discussions, on the other hand, are the perfect place to ask advice, share guides, and help with project configuration.
Another good thing about the discussion forum: you don't need to fill out an issue template.
This stack overflow answer helped me: https://stackoverflow.com/questions/63445821/ts-node-execute-typescript-with-module-import-and-module-defined
Updating my tsconfig.json to migrate from "module": "es6" to "module": "commonjs" allowed me to run my TypeScript file.
@a-h Thank you bro! you the man!
Remove "type": "module" from package.json
If remove module type, you cannot use imports in your .ts files
I'm having the same issue. how to fix, thx
This stack overflow answer helped me: https://stackoverflow.com/questions/63445821/ts-node-execute-typescript-with-module-import-and-module-defined
Updating my tsconfig.json to migrate from
"module": "es6"to"module": "commonjs"allowed me to run my TypeScript file.
Thanks! it's useful.
From #1007, use node --loader ts-node/esm ./my-script.ts if your tsconfig.json contains "module": "commonjs"
Most helpful comment
If remove module type, you cannot use imports in your .ts files