Anish Pradhan
Anish Pradhan

Reputation: 1

TypeError: Unknown file extension ".ts"

When I'm trying to write normal code with TS just like we do with JS. Then everytime while running the code with ts-node im facing an issue, and I don't how to solve this.

$ ts-node index.ts
  TypeError: Unknown file extension ".ts" for E:\Typescipt project\Practice\index.ts
  at Object.getFileProtocolModuleFormat [as file:] (node:internal/modules/esm/get_format:219:9)
  at defaultGetFormat (node:internal/modules/esm/get_format:245:36)
  at defaultLoad (node:internal/modules/esm/load:120:22)
  at async ModuleLoader.loadAndTranslate (node:internal/modules/esm/loader:483:32)
  at async ModuleJob._link (node:internal/modules/esm/module_job:115:19) {
    code: 'ERR_UNKNOWN_FILE_EXTENSION'
  }

and the code I'm running (index.ts) looks like this:

type Person = {
  name: string
}

const New: Person = {
  name: "Anish"
}

console.log(New.name);

I've checked my global path and even I tried to uninstall the ts and ts-node package and reinstall along with Node. But the issue is still there!

Upvotes: 0

Views: 205

Answers (1)

Tronic
Tronic

Reputation: 11

Install the latest node version v23.6.1 and run the program again by just typing node (file).ts It Works on Runtime! - That being said you don't need to use tsx or ts-node anymore as node is able to execute typescript in the runtime environment since the latest version changes

Upvotes: 1

Related Questions