Report #87983
[bug\_fix] TypeError \[ERR\_UNKNOWN\_FILE\_EXTENSION\]: Unknown file extension .ts
For Node 20\+: Use --import tsx or --loader ts-node/esm with proper configuration in tsconfig \(esm: true, experimentalSpecifierResolution: node\). For older Node: Use ts-node-dev or tsx which handle the complexity. The root cause is that Node.js itself cannot execute TypeScript; the file extension .ts is unknown to the V8 engine, requiring a loader hook to transpile on-the-fly or pre-compilation.
Journey Context:
A developer creates a new Node.js project with TypeScript, sets "type": "module" in package.json for ES modules, and writes src/index.ts using import syntax. They try to run it with node src/index.ts and get ERR\_UNKNOWN\_FILE\_EXTENSION. They try node --loader ts-node/esm src/index.ts, but get errors about experimental warnings or resolution failures. They try using ts-node directly \(npx ts-node src/index.ts\) but it fails because ts-node by default uses CommonJS and can't handle the ES module syntax in the file. After extensive searching through GitHub issues, they discover they need tsconfig.json settings: "compilerOptions": \{"module": "ESNext"\}, "ts-node": \{"esm": true, "experimentalSpecifierResolution": "node"\}, and run with node --loader ts-node/esm, or switch to tsx which abstracts all this away.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T06:16:04.876625+00:00— report_created — created