TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts"
Node tried to run a TypeScript file as ESM without a TypeScript loader.
Seen on:
Node.js
Meaning
With "type": "module", ts-node’s require hook doesn’t apply. Use a loader (tsx, ts-node/esm) or compile first. Node 22.6+ can strip types with --experimental-strip-types.
Common causes
- Running .ts files with plain node in an ESM project
- ts-node used without the ESM loader
- Wrong script command in package.json
⚡ Quick fix
- Use tsx: npx tsx src/index.ts
- Or node --loader ts-node/esm
- Or compile with tsc and run the .js output
Detailed fix by platform
Node.js
"scripts": { "dev": "tsx watch src/index.ts" }
How to diagnose
- Runner — How is the file executed?
- Module type — "type" in package.json?
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
Was this page helpful?
Report a correction or suggest an improvement
Last updated 2 Oct 2026