TypeError: Unknown file extension ".ts"

I've started a fresh T3-stack project and got this error when trying to run ts-node on any .ts file. err:
TypeError: Unknown file extension ".ts" for test.ts
at Object.getFileProtocolModuleFormat [as file:] (node:internal/modules/esm/get_format:176:9)
at defaultGetFormat (node:internal/modules/esm/get_format:219:36)
at defaultLoad (node:internal/modules/esm/load:133:22)
at async ModuleLoader.load (node:internal/modules/esm/loader:555:7)
at async ModuleLoader.moduleProvider (node:internal/modules/esm/loader:436:45)
at async ModuleJob._link (node:internal/modules/esm/module_job:106:19) {
code: 'ERR_UNKNOWN_FILE_EXTENSION'
}
TypeError: Unknown file extension ".ts" for test.ts
at Object.getFileProtocolModuleFormat [as file:] (node:internal/modules/esm/get_format:176:9)
at defaultGetFormat (node:internal/modules/esm/get_format:219:36)
at defaultLoad (node:internal/modules/esm/load:133:22)
at async ModuleLoader.load (node:internal/modules/esm/loader:555:7)
at async ModuleLoader.moduleProvider (node:internal/modules/esm/loader:436:45)
at async ModuleJob._link (node:internal/modules/esm/module_job:106:19) {
code: 'ERR_UNKNOWN_FILE_EXTENSION'
}
my package.json (removed some lines becaue of Discord's limits)
{
"name": "flashoid",
"version": "0.1.0",
"private": true,
"type": "module",
"scripts": {
"build": "next build",
"db:generate": "prisma migrate dev",
"db:migrate": "prisma migrate deploy",
"db:push": "prisma db push",
"db:studio": "prisma studio",
"dev": "next dev --port=8000",
"postinstall": "prisma generate",
"lint": "next lint",
"start": "next start"
},
"dependencies": {
"geist": "^1.3.0",
"next": "^14.2.4",
"next-auth": "^4.24.7",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"server-only": "^0.0.1",
"superjson": "^2.2.1",
"zod": "^3.23.3"
},
"devDependencies": {
"@types/eslint": "^8.56.10",
"@types/node": "^20.14.10",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"@typescript-eslint/eslint-plugin": "^8.1.0",
"@typescript-eslint/parser": "^8.1.0",
"ts-node": "^10.9.2",
"typescript": "^5.5.3"
},
"prisma": {
"seed": "ts-node --compiler-options {\"module\":\"CommonJS\"} prisma/seed.ts"
},
"ct3aMetadata": {
"initVersion": "7.37.0"
},
"packageManager": "[email protected]"
}
{
"name": "flashoid",
"version": "0.1.0",
"private": true,
"type": "module",
"scripts": {
"build": "next build",
"db:generate": "prisma migrate dev",
"db:migrate": "prisma migrate deploy",
"db:push": "prisma db push",
"db:studio": "prisma studio",
"dev": "next dev --port=8000",
"postinstall": "prisma generate",
"lint": "next lint",
"start": "next start"
},
"dependencies": {
"geist": "^1.3.0",
"next": "^14.2.4",
"next-auth": "^4.24.7",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"server-only": "^0.0.1",
"superjson": "^2.2.1",
"zod": "^3.23.3"
},
"devDependencies": {
"@types/eslint": "^8.56.10",
"@types/node": "^20.14.10",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"@typescript-eslint/eslint-plugin": "^8.1.0",
"@typescript-eslint/parser": "^8.1.0",
"ts-node": "^10.9.2",
"typescript": "^5.5.3"
},
"prisma": {
"seed": "ts-node --compiler-options {\"module\":\"CommonJS\"} prisma/seed.ts"
},
"ct3aMetadata": {
"initVersion": "7.37.0"
},
"packageManager": "[email protected]"
}
Solution:
AFAIK, it's ESM-related. I've just switched to tsx to avoid dealing with this
GitHub
GitHub - privatenumber/tsx: ⚡️ TypeScript Execute | The easiest way...
⚡️ TypeScript Execute | The easiest way to run TypeScript in Node.js - privatenumber/tsx
Jump to solution
2 Replies
Solution
none23
none233mo ago
AFAIK, it's ESM-related. I've just switched to tsx to avoid dealing with this
GitHub
GitHub - privatenumber/tsx: ⚡️ TypeScript Execute | The easiest way...
⚡️ TypeScript Execute | The easiest way to run TypeScript in Node.js - privatenumber/tsx
univers.js
univers.jsOP3mo ago
Yeah, TSX just works. Thanks.
Want results from more Discord servers?
Add your server