ERR_UNKNOWN_FILE_EXTENSION 🟩 Node.js

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

  1. Use tsx: npx tsx src/index.ts
  2. Or node --loader ts-node/esm
  3. Or compile with tsc and run the .js output

Detailed fix by platform

Node.js

  1. "scripts": { "dev": "tsx watch src/index.ts" }

How to diagnose

  1. Runner — How is the file executed?
  2. 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.