The error, verbatim
Jump to the fix ↓node:internal/modules/esm/get_format:189
throw new ERR_UNKNOWN_FILE_EXTENSION(ext, filepath);
^
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for C:\project\src\index.ts
at Object.getFileProtocolModuleFormat [as file:] (node:internal/modules/esm/get_format:189:9)
at defaultGetFormat (node:internal/modules/esm/get_format:232:36)
at defaultLoad (node:internal/modules/esm/load:145:22) {
code: 'ERR_UNKNOWN_FILE_EXTENSION'
}
The fix that worked
On Node 22.18 or newer, just run it. Older:
npx tsx src/index.tsNot it? Every cause, tested ↓Tested on
- Node
- 20.19.4, 22.5.1, 22.6.0, 22.18.0, 24.14.0; 20.20.2, 22.17.1, 22.18.0, 24.22.2, 26.13.0 (Linux, November 8)
- ts-node
- 10.9.2
- tsx
- 4.23.15
- TypeScript
- 5.9.3 and 7.0.2
- OS
- Windows 11 Pro
✓ Last re-run on GitHub Actions · see the run · all repros
Contents
The fix
Run your Node version first, because this error disappears on its own from Node 22.18:
node --versionOn Node 22.18 or newer (including Node 24), run the file directly. No loader, no flag, no ts-node:
node src/index.tsOn anything older, install tsx and run the file through it:
npm i -D tsx
npx tsx src/index.tsFor an npm script, or where you need Node’s own flags, load tsx into Node instead:
{ "scripts": { "dev": "node --import tsx src/index.ts" } }Which Node version does what
I ran the same file, unchanged, on six Node versions:
| Node | node src/index.ts |
With --experimental-strip-types |
|---|---|---|
| 20.19.4 | ERR_UNKNOWN_FILE_EXTENSION |
flag doesn’t exist |
| 22.5.1 | ERR_UNKNOWN_FILE_EXTENSION |
bad option |
| 22.6.0 | ERR_UNKNOWN_FILE_EXTENSION |
runs |
| 22.18.0 | runs | runs |
| 24.14.0 | runs | runs |
| 26.11.1 | runs | runs |
One flag did change on 26: --experimental-transform-types was removed. The rest of the 24 to 26 changes are in Node 26 vs Node 24, tested.
So there are three eras, and the answer you find online depends entirely on which one it was written in: before 22.6 Node could not load a .ts file at all, from 22.6 it could behind a flag, and from 22.18 it does it by default.
Why it happens
Node decides how to load a file from its extension. In an ES module project, the list is short: .js, .mjs, .cjs, .json, .node and, on new enough versions, .ts, .mts and .cts. Anything else is refused by name before a single line is read, which is why the stack trace points at get_format and never at your code.
Newer Node versions add TypeScript by stripping the types: the type annotations are replaced with whitespace and the result is run as plain JavaScript. Nothing is type-checked and nothing is compiled, which is why it’s fast and also why it can’t handle everything (see the trap below).
Why ts-node hits it too
This is the version most people actually have, because the error arrives from a tool that is supposed to prevent it:
npx ts-node src/index.ts
TypeError: Unknown file extension ".ts" for C:\project\src\index.ts
at Object.getFileProtocolModuleFormat [as file:] (node:internal/modules/esm/get_format:189:9)
code: 'ERR_UNKNOWN_FILE_EXTENSION'
ts-node hooks into CommonJS loading. The moment your package.json has "type": "module", your .ts file is an ES module, a different loader handles it, and ts-node’s hook is never consulted. Node reaches the extension check and refuses.
Proof it’s the module system and not the file: I removed "type": "module" from package.json and ran the identical command on the identical Node 20, and it printed hello world.
What didn’t work
The trap after the fix
Type stripping is not compilation. Syntax that has to generate JavaScript, like enum and namespace, is refused:
SyntaxError [ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX]: TypeScript enum is not supported in strip-only mode
That’s Node 24 running a file whose only crime is one enum. The ways past it, all five variants reproduced: TypeScript enum is not supported in strip-only mode.
A .ts package in node_modules: a different error
Once your own .ts files run, a monorepo can still trip over a dependency that ships TypeScript source ("main": "index.ts"). On November 8, 2026 I imported the same small TypeScript package two ways, installed into node_modules and linked through npm workspaces, on five Node releases:

- Copied into
node_modules, as a published package would be, it failed on 22.18.0, 24.22.2 and 26.13.0 withERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING: “Stripping types is currently unsupported for files under node_modules”. Node strips types in your code, deliberately not in your dependencies. - Linked through npm workspaces, the same package ran on all three. The link points to the package’s real folder outside
node_modules, and Node uses that real path, so the rule doesn’t apply. - The boundary for your own files is exact: 22.17.1 still threw
ERR_UNKNOWN_FILE_EXTENSION, and 22.18.0 ran the file.
For a TypeScript dependency, either keep it as a workspace package, compile it to JavaScript before publishing (main pointing at .js), or run the app with tsx, which loads TypeScript from node_modules too:
npx tsx src/uses-lib.tsTest runners
node --testfollows the same rule asnodeitself: on Node 20 the.tstest file fails, on Node 24 it runs.- Mocha 12 strips types itself, so a
.tstest ran on Node 20 as well, but theenumfile still failed there withERR_UNSUPPORTED_TYPESCRIPT_SYNTAX.
Run it yourself
The November 8 version matrix is the unknown-file-extension-ts folder in nk-repro (run 42507477762). The original project:
The project I used is on GitHub, so you can trigger the error on your own machine in under a minute:
git clone https://github.com/nils44344/node-ts-error-repros
cd node-ts-error-repros/01-unknown-file-extension
npm install && npm run repro
Setup
A three-line TypeScript file and a package.json with "type": "module", run unchanged on five Node versions installed side by side, with ts-node 10.9.2, tsx 4.23.15, Mocha 12.0.2, and TypeScript 5.9.3 and 7.0.2. Every result above is the actual terminal output, including the failures.
— N.K., end of entry No.012