Skip to content
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

TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" #2122

Open
luyifo opened this issue Jun 12, 2024 · 6 comments
Open

TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" #2122

luyifo opened this issue Jun 12, 2024 · 6 comments

Comments

@luyifo
Copy link

luyifo commented Jun 12, 2024

Search Terms

When the node version is 18.20.0, running TS-node --esm **.ts displays TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts". Runs successfully after the Node version is reduced to 16.20.2.

PS D:\Testspace\ts-node-demo> pn dev

> [email protected] dev D:\Testspace\ts-node-demo
> ts-node-esm src/index.ts

TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for D:\Testspace\ts-node-demo\src\index.ts
    at new NodeError (node:internal/errors:405:5)
    at Object.getFileProtocolModuleFormat [as file:] (node:internal/modules/esm/get_format:136:11)
    at defaultGetFormat (node:internal/modules/esm/get_format:182:36)
    at defaultLoad (node:internal/modules/esm/load:101:20)
    at nextLoad (node:internal/modules/esm/hooks:864:28)
    at load (D:\Testspace\ts-node-demo\node_modules\.pnpm\t[email protected]_@[email protected][email protected]\node_modules\ts-node\dist\child\child-loader.js:19:122)
    at nextLoad (node:internal/modules/esm/hooks:864:28)
    at Hooks.load (node:internal/modules/esm/hooks:447:26)
    at MessagePort.handleMessage (node:internal/modules/esm/worker:196:24)
    at [nodejs.internal.kHybridDispatch] (node:internal/event_target:786:20) {
  code: 'ERR_UNKNOWN_FILE_EXTENSION'
}
 ELIFECYCLE  Command failed with exit code 1.
PS D:\Testspace\ts-node-demo> nvm list

  * 18.20.0 (Currently using 64-bit executable)
    16.20.2
PS D:\Testspace\ts-node-demo> nvm use 16.20.2
Now using node v16.20.2 (64-bit)
PS D:\Testspace\ts-node-demo> pn dev

> [email protected] dev D:\Testspace\ts-node-demo
> ts-node-esm src/index.ts

hello world
PS D:\Testspace\ts-node-demo> 

Expected Behavior

Actual Behavior

Steps to reproduce the problem

Minimal reproduction

Specifications

  • ts-node version: 10.9.2
  • node version: 18.20.0
  • TypeScript version: 5.4.5
  • tsconfig.json, if you're using one:
{
  "compilerOptions": {
    "rootDir": "./src",
    "target": "es2016", 
    "module": "NodeNext", 
    "moduleResolution": "NodeNext",
    "esModuleInterop": true, 
    "forceConsistentCasingInFileNames": true, 
    "strict": true, 
    "skipLibCheck": true, 
    "verbatimModuleSyntax": true,
    "declaration": true,
    "declarationMap": true,
    "sourceMap": true
  }
}
  • package.json:
{
  "type": "module",
  "name": "ts-node-demo",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "dev": "ts-node-esm src/index.ts",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "ts-node": "^10.9.2",
    "typescript": "^5.4.5"
  }
}
  • Operating system and version: Windows 11 Pro 10.0.22631 Build 22631
  • If Windows, are you using WSL or WSL2?:
@etulikov
Copy link

I had the same issue, downgrade Node to 18.18 help.
My engines:

"engines": {
    "node": ">=18.18.0 <18.19.0"
  },

@EvilCodeMorty
Copy link

Have you solved this problem?I switched the versions of 22,18 and 16 with different problems, and the configuration file has been modified, but it still doesn't work

@EvilCodeMorty
Copy link

"module": "CommonJS", "esModuleInterop": true,

@EvilCodeMorty
Copy link

My code compilation is no problem, I specially configured a file for "ts-node", code compilation is another file, anyway just to see the state of writing code, so I specially configured a file for "ts-node", compilation is another file;"tsconfig.dev.json"and"tsconfig.json"

@EvilCodeMorty
Copy link

"dev": "cross-env TS_NODE_PROJECT=tsconfig.dev.json nodemon --exec ts-node src/main.ts",

1 similar comment
@EvilCodeMorty
Copy link

"dev": "cross-env TS_NODE_PROJECT=tsconfig.dev.json nodemon --exec ts-node src/main.ts",

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants