ERR_UNKNOWN_FILE_EXTENSION
node
module_error
ai_generated
true
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension '.ts'
ID: node/err-unknown-file-extension
88%Fix Rate
90%Confidence
50Evidence
2023-01-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 20 | active | — | — | — |
Root Cause
Node.js can't handle .ts/.jsx file directly. Need loader or compilation step.
genericWorkarounds
-
95% success Use tsx or ts-node for TypeScript execution
Use tsx or ts-node for TypeScript execution
-
85% success Use --loader flag with ts-node/esm
node --loader ts-node/esm script.ts
Dead Ends
Common approaches that don't work:
-
Rename .ts to .js
80% fail
Loses TypeScript type checking entirely
-
Add type:module to package.json
70% fail
Doesn't help — Node still can't parse TypeScript
Error Chain
Preceded by: