> ## Content Index
> Fetch the complete content index at: https://sudosecurity.org/llms.txt
> Use this file to discover other available public pages before exploring further.

# Node Runs TypeScript Now. Here's Exactly What It Strips, What It Refuses, and What It Costs
- URL: https://sudosecurity.org/node-typescript-type-stripping/
- Published: 2026-11-29T14:00:00.000Z
- Updated: 2026-11-29T14:00:00.000Z
- Description: Node 24 and 26 run .ts files with no build step and no flags, by replacing types with whitespace. I ran eleven test cases, the TypeScript 7 compiler and tsx against both versions: enums, parameter properties and type imports without the type keyword all break, type errors run anyway, and...
- Author: Santhdium
- Tags: TypeScript, Node.js, JavaScript, Runtimes, Developer Tools, Compilers, Backend Development

For about a decade, running a TypeScript file in Node meant choosing a build step. `tsc` to a `dist/` folder, `ts-node` and its tsconfig edge cases, then `esbuild`\-based runners like `tsx`. Every one of them is a dependency, a config file, and a source map that's slightly wrong when you need it most.

Now you type `node server.ts` and it runs. No flag, no loader, no package. Per the Node.js docs, type stripping was "enabled by default" in v23.6.0 and v22.18.0, stopped printing an experimental warning in v24.3.0, and is marked "Stability: 2 - Stable" since v25.2.0 and v24.12.0\. It's an easy feature to misread, though. Node doesn't compile TypeScript. It deletes it. That one design choice explains everything that works, everything that breaks, and every surprise below.

## How Node's TypeScript Type Stripping Works

The docs are blunt about it: "Node.js will replace TypeScript syntax with whitespace, and no type checking is performed." Node exposes the same transform as `stripTypeScriptTypes()` in `node:module`, so you can watch it happen. I swapped spaces for `·` so you can see them:

```js
import { stripTypeScriptTypes } from "node:module";

const source = `function greet(user: User, role: Role = "viewer"): string {
  return user.name as string;
}`;
console.log(stripTypeScriptTypes(source).replaceAll(" ", "·"));

```

```text
function·greet(user······,·role·······=·"viewer")·········{
··return·user.name··········;
}
(node:1) ExperimentalWarning: stripTypeScriptTypes is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)

```

Every annotation turns into the same number of spaces. Nothing moves. That's the clever part: line and column numbers in the running JavaScript are identical to the source, so Node needs no source maps at all. I threw an error from line 6 of a file with a type alias at the top and got the exact position back:

```text
  if (p.tags.length === 0) throw new Error("no tags");
Error: no tags
    at parse (file:///w/cases/10-stack-line.ts:6:34)

```

Under the hood it's Amaro, which its README describes as "a Node.js wrapper around the SWC TypeScript parser and type stripper," compiled to WebAssembly (`process.versions.amaro` reports 1.1.11 on Node 26.13.1). The docs note that if WebAssembly is unavailable, "parsing throws ERR\_WEBASSEMBLY\_NOT\_SUPPORTED." There's no fallback. You also can't use it in the REPL, with `--check`, or with `inspect`.

## Eleven Cases on Node 24 and 26

I wrote eleven small files covering the syntax people actually use and ran each one on `node:24-slim` (v24.22.3) and `node:26-slim` (v26.13.1). Both versions gave identical results:

```text
## v24.22.3
01-erasable                    ada (admin)
02-type-error-still-runs       string 80801
03-enum                        SyntaxError [ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX]: TypeScript enum is not supported in strip-only mode
04-param-props                 SyntaxError [ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX]: TypeScript parameter property is not supported in strip-only mode
05-namespace-value             SyntaxError [ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX]: TypeScript namespace declaration is not supported in strip-only mode
06-import-no-type-keyword      SyntaxError: The requested module './types.ts' does not provide an export named 'Order'
07-import-type-keyword         1.0 9.5
08-decorator                   SyntaxError: Invalid or unexpected token
09-extensionless-import        Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/w/cases/types' imported from /w/cases/09-extensionless-import.ts
10-stack-line                  Error: no tags
11-ts-in-node-modules          Error [ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING]: Stripping types is currently unsupported for files under node_modules, for "file:///w/node_module

```

| Case                                             | Result                        | Why                                                           |
| ------------------------------------------------ | ----------------------------- | ------------------------------------------------------------- |
| Interfaces, type aliases, annotations, satisfies | Runs                          | Pure annotation, erases cleanly                               |
| A type error (const port: number = "8080")       | **Runs**, prints string 80801 | No type checking, ever                                        |
| enum                                             | Error                         | Needs generated JavaScript                                    |
| Constructor parameter properties                 | Error                         | Needs generated assignments                                   |
| namespace with values                            | Error                         | Needs a generated object                                      |
| import { Order } where Order is a type           | Error at runtime              | Node can't tell it's a type, so it looks for a runtime export |
| import { type Order }                            | Runs                          | Explicitly marked, so it's erased                             |
| Decorators                                       | Error                         | Not in JavaScript yet, and Node doesn't polyfill              |
| import "./types" (no extension)                  | Error                         | ESM needs the real file name                                  |
| .ts inside node\_modules                         | Error                         | Refused on purpose                                            |

Line two is the one that will bite people who skim the release notes. `"8080" + 1` is `"80801"`, and Node ran it happily because nothing in the pipeline knows what `: number` means. Type stripping gives you TypeScript's syntax without its safety. You still need `tsc` in CI, or you're writing JavaScript with decorative comments.

The node\_modules refusal is policy, not a technical limit. The docs say it exists "to discourage package authors from publishing packages written in TypeScript." Publish compiled JavaScript with `.d.ts` files, same as always.

> **We recommend reading** [TypeScript 7.0: The Go Rewrite Lands](https://sudosecurity.org/typescript-7-0-official-release/) to continue reading our selection of content. The checker you'll pair with this is now the Go-native TypeScript 7, and that's covered here.

[TypeScript 7.0: The Go Rewrite Lands](https://sudosecurity.org/typescript-7-0-official-release/) TypeScript 7 is the Go-native rewrite: \~10x faster checking, project service architecture, and a new CLI. What changed for real codebases. SudoSecurity · Landen

## The Flag That Used to Fix Enums Is Gone

Node 22 and 24 had an escape hatch, `--experimental-transform-types`, that did generate code for enums and namespaces. On Node 24 it still works, with a warning:

```text
(node:1) ExperimentalWarning: Transform Types is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
2

```

On Node 26 it's gone:

```text
node: bad option: --experimental-transform-types

```

The Node 26 docs record it in the history table: "v26.0.0: Removed --experimental-transform-types flag." If you lean on it, your Node 26 upgrade breaks at startup, before your code even loads. The supported path for full TypeScript, per the same page, is a third-party runner: "use a third-party package," with `tsx` as the example.

## Make tsc Enforce the Same Rules

The good news is that the TypeScript compiler can flag every Node-incompatible construct ahead of time. The Node docs recommend TypeScript 5.8 or newer with these settings, and I added `strict` and an empty `types` list:

```json
{
  "compilerOptions": {
    "noEmit": true,
    "target": "esnext",
    "module": "nodenext",
    "rewriteRelativeImportExtensions": true,
    "erasableSyntaxOnly": true,
    "verbatimModuleSyntax": true,
    "strict": true,
    "types": []
  },
  "include": ["cases/*.ts"]
}

```

TypeScript 7.0.2 (the current `latest` on npm, and the Go-native compiler) against the same eleven files:

```text
cases/02-type-error-still-runs.ts(1,7): error TS2322: Type 'string' is not assignable to type 'number'.
cases/03-enum.ts(1,6): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
cases/04-param-props.ts(2,15): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
cases/04-param-props.ts(2,37): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
cases/05-namespace-value.ts(1,11): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
cases/06-import-no-type-keyword.ts(1,10): error TS1484: 'Order' is a type and must be imported using a type-only import when 'verbatimModuleSyntax' is enabled.
cases/09-extensionless-import.ts(1,25): error TS2835: Relative import paths need explicit file extensions in ECMAScript imports when '--moduleResolution' is 'node16' or 'nodenext'. Did you mean './types.js'?

```

That's the type error, the enum, both parameter properties, the namespace, the type import missing its `type` keyword, and the extensionless import, each with a file and column. `erasableSyntaxOnly` is the flag doing the heavy lifting. It exists for exactly this, and it rejects anything that would need generated code.

Two cases get past it. Decorators type-check fine, because TypeScript supports the TC39 decorators proposal, but Node rejects them because JavaScript doesn't have them yet. And the `node_modules` refusal is a runtime policy `tsc` knows nothing about. Both fail loudly the first time you run the file, so they won't sneak into production. They just won't show up in CI unless CI also runs the code.

## What It Costs at Startup

Fifteen runs of each, median, inside the container. The small file is case 01\. The big file is a generated 4,502-line module of 500 interfaces and 500 typed functions.

```text
## node:24-slim
node small.mjs (plain JS)                  33 ms
node small.ts (type stripping)             75 ms
node --no-strip-types small.mjs            29 ms
tsx small.ts                              153 ms
node --import tsx small.ts                 73 ms
node big.mjs (5,000 lines, tsc output)     40 ms
node big.ts (5,000 lines, stripped)       142 ms
tsx big.ts                                164 ms
tsc --noEmit big.ts (type check only)     456 ms
## node:26-slim
node small.mjs (plain JS)                  33 ms
node small.ts (type stripping)             78 ms
node --no-strip-types small.mjs            35 ms
tsx small.ts                              133 ms
node --import tsx small.ts                 77 ms
node big.mjs (5,000 lines, tsc output)     41 ms
node big.ts (5,000 lines, stripped)       151 ms
tsx big.ts                                156 ms
tsc --noEmit big.ts (type check only)     416 ms

```

| Node 26                           | Small file | 4,502-line file |
| --------------------------------- | ---------- | --------------- |
| Plain JavaScript (tsc output)     | 33 ms      | 41 ms           |
| node file.ts (built-in stripping) | 78 ms      | 151 ms          |
| node --import tsx file.ts         | 77 ms      | —               |
| tsx file.ts (CLI)                 | 133 ms     | 156 ms          |
| tsc --noEmit (TypeScript 7 check) | —          | 416 ms          |

Built-in stripping adds about 40 ms on a tiny file, mostly loading the WebAssembly parser, and about 110 ms on a big one. That's a one-time cost per process, paid at startup. A long-running server will never notice. A CLI tool that runs hundreds of times in a shell loop will.

`tsx` as a CLI was the slowest small-file option because it spawns a child Node process. Loaded with `--import`, it landed right next to built-in stripping. If you need enums or path aliases, that's how to run it.

The numbers also show what precompiling buys you. A shipped `.js` file starts in a quarter of the time of the stripped `.ts` version of the same code. For production containers, compiling at build time is still the fastest start you can get. Type stripping is about removing the build step from development, scripts and tooling, not about making production faster.

> **We recommend reading** [Node 26 Is LTS and Temporal Is Finally On by Default](https://sudosecurity.org/nodejs-26-lts-upgrade/) to continue reading our selection of content. If you're moving to 26 for this, here's the rest of what changes on the upgrade.

[Node 26 Is LTS and Temporal Is Finally On by Default](https://sudosecurity.org/nodejs-26-lts-upgrade/) Node.js 26 is LTS as of October 28\. Temporal enabled by default, V8 14.6, legacy stream modules removed. What breaks on upgrade. SudoSecurity · Santhdium

## Feature Detection, CommonJS and the --check Trap

A few more behaviors that matter once this goes beyond a single script:

```bash
#!/bin/bash
# Extra behaviors: runtime feature flag, CommonJS .cts, --check, --no-strip-types, eval input.
cd /w/more
echo "## $(node --version)"
node features.mjs
node --no-strip-types features.mjs
node cjs-main.cts
node --check cjs-main.cts 2>&1 | grep -m1 -E 'Error|error' || echo "--check: no error"
node --no-strip-types cjs-main.cts 2>&1 | grep -m1 -E '^[A-Za-z]*Error' 
node --input-type=module-typescript -e 'const n: number = 41; console.log("--eval with types:", n + 1);' 2>&1 | head -1

```

```text
## v24.22.3
process.features.typescript = "strip"
process.features.typescript = false
require() of .cts from .cts: 5
SyntaxError: Missing initializer in const declaration
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".cts" for /w/more/cjs-main.cts
--eval with types: 42
## v26.13.1
process.features.typescript = "strip"
process.features.typescript = false
require() of .cts from .cts: 5
SyntaxError: Missing initializer in const declaration
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".cts" for /w/more/cjs-main.cts
--eval with types: 42

```

- **Feature detection.** `process.features.typescript` is `"strip"` when type stripping is on and `false` under `--no-strip-types`. A CLI tool can check it at startup and print a clear error, instead of a confusing `SyntaxError`, when someone runs it on an old Node or with stripping disabled.
- **CommonJS works.** A `.cts` file can `require("./math.cts")` another `.cts` file. As the docs say, the extension is mandatory in `require()` too.
- **`node --check` doesn't strip.** It parsed the valid TypeScript file as JavaScript and failed with `SyntaxError: Missing initializer in const declaration`. If your CI or a pre-commit hook runs `node --check` over every source file as a quick syntax test, it will reject perfectly good `.ts` files. Use `tsc --noEmit` for TypeScript files.
- **`--no-strip-types` makes `.cts` an unknown extension.** Code that runs fine normally fails with `ERR_UNKNOWN_FILE_EXTENSION`. That's worth knowing if a deployment environment sets `NODE_OPTIONS` you didn't choose.
- **`--eval` takes types** with `--input-type=module-typescript`, which is handy for one-liners in shell scripts.

Node 24.22.3 and 26.13.1 behaved identically on every one of these.

## Writing TypeScript Node Can Run

The rules, in the form I'd put in a team README:

- **Use `as const` objects or union types instead of `enum`.** `const Level = { Debug: 0, Info: 1 } as const` plus `type Level = typeof Level[keyof typeof Level]` gives you the same thing, in erasable form.
- **Write constructor assignments by hand.** Parameter properties are sugar for `this.host = host`. Write the line out.
- **Mark type imports.** `import type { X }` or `import { type X, y }`. `verbatimModuleSyntax` enforces it.
- **Use real extensions.** `import "./db.ts"`. With `rewriteRelativeImportExtensions`, `tsc` rewrites them to `.js` if you also emit.
- **Replace tsconfig `paths` with subpath imports.** Node ignores `tsconfig.json` entirely. The docs point to `package.json` imports that "need to start with #".
- **Pick a module system per file.** `.ts` follows the nearest `package.json` `"type"`. `.mts` is always ESM, `.cts` always CommonJS, and `.tsx` isn't supported at all.

## What This Doesn't Cover

- **Deno and Bun.** Both run TypeScript with their own transpilers and different rules. Bun, for example, handles enums.
- **Frontend builds.** Vite, esbuild and friends still own JSX, bundling and downleveling. Type stripping doesn't do any of that.
- **Library publishing.** Compiling and shipping `.d.ts` files is unchanged.
- **Large monorepo startup.** I measured single files. A thousand-file app strips every file it loads, and that cost scales with code size. Measure your own.

## The Actual Point

`node file.ts` is real, stable and fast enough. What makes it work is also what limits it: Node erases types with whitespace and never reads your tsconfig, so anything that needs generated code fails, and anything that's a type error runs anyway. Turn on `erasableSyntaxOnly` and `verbatimModuleSyntax`, keep `tsc --noEmit` in CI, stop writing enums, and you can delete a build step from every script and dev server you own. Keep compiling for production, because plain JavaScript still starts faster.

*Sources: the Node.js v26.13.1 "Modules: TypeScript" documentation at nodejs.org, and the typescript and tsx packages on the npm registry. All cases and timings were run by me on the official node:24-slim and node:26-slim images with TypeScript 7.0.2 and tsx 4.23.15\. Every code and output block above is reproduced verbatim from those test files and runs; the README rules near the end are guidance and weren't run as code.*