-
-
Notifications
You must be signed in to change notification settings - Fork 532
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error: unknown file extension .ts #1062
Comments
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.
|
Estou tendo o mesmo problema também
|
My earlier suggestion should point you in the right direction.
…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>
.
|
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 |
nope, same problem with import. |
I created a template repo which can be used by anyone who has trouble initializing |
Closing as this is not a |
@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 Since this is not a bug and nothing needs to change in 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 |
@a-h Thank you bro! you the man! |
I'm having the same issue. how to fix, thx |
Thanks! it's useful. |
From #1007, use |
I remove type: module from package json and it work |
This solution resolves my two problems which are "import" syntax-error outside module and unknown file extensions ".ts"!!! Thank you very much for saving my time. 😁 |
Add this to the tsconfig.json:
and make sure to start the server with
It is crazy how hard it was for me to find this. This will allow you to use imports as well as use typescript. |
Yup that works!! |
Real quick follow up to this - running with this makes my code ~8x slower than |
set the value of module to
|
ts-node --skip-project scripts/yourFile.ts |
For anyone who is running into this issue on CI or on Node.js 16.12.0, it seems like this latest version has made some changes to the hooks API 😱 https://github.com/nodejs/node/releases/tag/v16.12.0 Also mentioned here: |
Supported by ts-node 10.3.1 |
ts-node error ❌
ESM solution ✅
{
"name": "patch-package-in-action",
"version": "1.0.0",
"description": "patch-package in action",
"main": "./src/app.ts",
"type": "module",
"scripts": {
"app-esm": "npx ts-node-esm ./src/app.ts",
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/web-fullstack/patch-package-in-action.git"
},
"author": "xgqfrms",
"license": "MIT",
"dependencies": {
"lodash-es": "^4.17.21",
"typescript": "^5.0.2"
},
"devDependencies": {
"@types/lodash-es": "^4.17.7",
"app-node-env": "^1.4.7",
"rimraf": "^4.4.0",
"ts-node": "^10.9.1"
}
}
{
"compilerOptions": {
"target": "ESNext",
"module": "ESNext",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true
}
}
// ./src/app.ts
import {toString} from "lodash-es";
type Obj = {
[key: string]: any;
}
const obj: Obj = {
name: 'xgqfrms',
country: 'China',
language: 'zh-hans',
};
const str = toString(obj);
console.log(`toString =`, str1); refs |
I just |
@dfenerski thanks |
"ts-node": {
"esm": true
} This worked for me. Thanks, @retrotechie 🚀 |
|
Using node 20 with sveltekit, this works |
Thank you😘 |
I need |
same error in 2023 anyone code a tsx launch file for vscode that allows debugging? |
If you suddenly started getting this issue, this might be the cause: #2094 |
for using esm add these
} it worked for me add this to your compilerOptions Nb : Option 'allowImportingTsExtensions' can only be used when either 'noEmit' or 'emitDeclarationOnly' is set.ts |
That's not true. ESM and CJS (CommonJS) are two different things, changing |
I got this same error ( I find it really odd that .ts files are not recognised by default. Surely ts-node should know how to handle .ts files? |
This is what worked for me. Not even
Let me just say that the entire ESM situation in Node.JS is a catastrophe. It created so much pain, incompatibility, lost hours. I don't understand why some decisions were made that contributed to this pain. It's probably not as bad as Python2 and Python3 but very close! |
…1977) This pull request resolves #1926 and prevents issues like it from happening in the future ## Rationale for this PR This PR changes the TypeScript execution package for use in scripts like `build:registry` from `ts-node` to `tsx`. This is because `ts-node` has many difficult quirks to work through (and is slow). In addition, it also has a difficult to understand error for newcomers that *is* reproducible. ### The ts-node error As shown in #1926, using `ts-node` (specifically in `build:registry`) results in this error: `Unknown file extension ".ts" for /ui/apps/www/scripts/build-registry.ts`. There are many issues in the `ts-node` repository documenting this problem: * TypeStrong/ts-node/issues/1062 * TypeStrong/ts-node/issues/2033 * TypeStrong/ts-node/issues/1997 Switching the typescript-in-node system to `tsx`, which uses esbuild under the hood, resolves this error. This PR shouldn't affect tests, representation, etc. and is merely a change of build tools. There is no urgent need to merge this. I accidentally deleted the head repository on #1937. That will not happen again.
for me worked the opposite ( updated node to the latest 21.x version ) "ts-node": {
"esm": false,
"compilerOptions": {
"module": "NodeNext"
}
}, |
tsconfig.json
package.json
|
…#1977) This pull request resolves #1926 and prevents issues like it from happening in the future ## Rationale for this PR This PR changes the TypeScript execution package for use in scripts like `build:registry` from `ts-node` to `tsx`. This is because `ts-node` has many difficult quirks to work through (and is slow). In addition, it also has a difficult to understand error for newcomers that *is* reproducible. ### The ts-node error As shown in #1926, using `ts-node` (specifically in `build:registry`) results in this error: `Unknown file extension ".ts" for /ui/apps/www/scripts/build-registry.ts`. There are many issues in the `ts-node` repository documenting this problem: * TypeStrong/ts-node/issues/1062 * TypeStrong/ts-node/issues/2033 * TypeStrong/ts-node/issues/1997 Switching the typescript-in-node system to `tsx`, which uses esbuild under the hood, resolves this error. This PR shouldn't affect tests, representation, etc. and is merely a change of build tools. There is no urgent need to merge this. I accidentally deleted the head repository on #1937. That will not happen again.
…#1977) This pull request resolves #1926 and prevents issues like it from happening in the future ## Rationale for this PR This PR changes the TypeScript execution package for use in scripts like `build:registry` from `ts-node` to `tsx`. This is because `ts-node` has many difficult quirks to work through (and is slow). In addition, it also has a difficult to understand error for newcomers that *is* reproducible. ### The ts-node error As shown in #1926, using `ts-node` (specifically in `build:registry`) results in this error: `Unknown file extension ".ts" for /ui/apps/www/scripts/build-registry.ts`. There are many issues in the `ts-node` repository documenting this problem: * TypeStrong/ts-node/issues/1062 * TypeStrong/ts-node/issues/2033 * TypeStrong/ts-node/issues/1997 Switching the typescript-in-node system to `tsx`, which uses esbuild under the hood, resolves this error. This PR shouldn't affect tests, representation, etc. and is merely a change of build tools. There is no urgent need to merge this. I accidentally deleted the head repository on #1937. That will not happen again.
Switching to tsx was the only thing that worked for me. Now it's as simple as |
…hadcn-ui#1977) This pull request resolves shadcn-ui#1926 and prevents issues like it from happening in the future ## Rationale for this PR This PR changes the TypeScript execution package for use in scripts like `build:registry` from `ts-node` to `tsx`. This is because `ts-node` has many difficult quirks to work through (and is slow). In addition, it also has a difficult to understand error for newcomers that *is* reproducible. ### The ts-node error As shown in shadcn-ui#1926, using `ts-node` (specifically in `build:registry`) results in this error: `Unknown file extension ".ts" for /ui/apps/www/scripts/build-registry.ts`. There are many issues in the `ts-node` repository documenting this problem: * TypeStrong/ts-node/issues/1062 * TypeStrong/ts-node/issues/2033 * TypeStrong/ts-node/issues/1997 Switching the typescript-in-node system to `tsx`, which uses esbuild under the hood, resolves this error. This PR shouldn't affect tests, representation, etc. and is merely a change of build tools. There is no urgent need to merge this. I accidentally deleted the head repository on shadcn-ui#1937. That will not happen again.
…#1977) This pull request resolves #1926 and prevents issues like it from happening in the future ## Rationale for this PR This PR changes the TypeScript execution package for use in scripts like `build:registry` from `ts-node` to `tsx`. This is because `ts-node` has many difficult quirks to work through (and is slow). In addition, it also has a difficult to understand error for newcomers that *is* reproducible. ### The ts-node error As shown in #1926, using `ts-node` (specifically in `build:registry`) results in this error: `Unknown file extension ".ts" for /ui/apps/www/scripts/build-registry.ts`. There are many issues in the `ts-node` repository documenting this problem: * TypeStrong/ts-node/issues/1062 * TypeStrong/ts-node/issues/2033 * TypeStrong/ts-node/issues/1997 Switching the typescript-in-node system to `tsx`, which uses esbuild under the hood, resolves this error. This PR shouldn't affect tests, representation, etc. and is merely a change of build tools. There is no urgent need to merge this. I accidentally deleted the head repository on #1937. That will not happen again.
…#1977) This pull request resolves #1926 and prevents issues like it from happening in the future ## Rationale for this PR This PR changes the TypeScript execution package for use in scripts like `build:registry` from `ts-node` to `tsx`. This is because `ts-node` has many difficult quirks to work through (and is slow). In addition, it also has a difficult to understand error for newcomers that *is* reproducible. ### The ts-node error As shown in #1926, using `ts-node` (specifically in `build:registry`) results in this error: `Unknown file extension ".ts" for /ui/apps/www/scripts/build-registry.ts`. There are many issues in the `ts-node` repository documenting this problem: * TypeStrong/ts-node/issues/1062 * TypeStrong/ts-node/issues/2033 * TypeStrong/ts-node/issues/1997 Switching the typescript-in-node system to `tsx`, which uses esbuild under the hood, resolves this error. This PR shouldn't affect tests, representation, etc. and is merely a change of build tools. There is no urgent need to merge this. I accidentally deleted the head repository on #1937. That will not happen again.
Expected Behavior
Load typescript files
Actual Behavior
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
The text was updated successfully, but these errors were encountered: