Node.js Reference ยท CLI Flags
Node.js --experimental-strip-types flag
Reference for running TypeScript files directly in Node.js: type stripping, --experimental-transform-types for enums, the limits, and how to turn it off.
Node.js can run .ts files without a build step by stripping the type annotations before handing the code to V8. The types are replaced with blank space, so line and column numbers stay the same and no source map is needed. Node does not check the types: it simply removes them.
In current LTS releases (including Node.js 24) type stripping is enabled by default, so node app.ts just works. The flag --experimental-strip-types is still accepted and makes the intent explicit; --no-experimental-strip-types turns the feature off. For syntax that needs real code generation, such as enum, add --experimental-transform-types.
// shell: node app.ts
Try it
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.
Syntax
// shell node app.ts node --experimental-strip-types app.ts node --experimental-transform-types app.ts node --no-experimental-strip-types app.ts
| Name | Description |
|---|---|
--experimental-strip-types |
Removes erasable type syntax from .ts, .mts and .cts files. On by default in current releases. |
--experimental-transform-types |
Also compiles TypeScript-only constructs that produce code (enum, namespace with values, parameter properties). Implies stripping. |
--no-experimental-strip-types |
Disables the feature; .ts files then fail to load. |
Returns: nothing. Check process.features.typescript, which is false, 'strip' or 'transform'.
Errors: unsupported syntax in strip-only mode throws ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX. Importing a .ts file from inside node_modules throws ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING.
Usage notes
- No type checking. Run
tsc --noEmit(or your editor and CI) to check types; Node only removes them. The second example runs a deliberately wrong program. - Use full file extensions in imports:
import { f } from './util.ts', not'./util'. Node does not guess extensions. Intsconfig.json, enableallowImportingTsExtensionsandrewriteRelativeImportExtensions(orerasableSyntaxOnly) so the compiler agrees. - Type-only imports need
import type(orimport { type X }), otherwise Node tries to load a value that does not exist at runtime. - Erasable syntax only in strip mode: interfaces, type aliases, annotations, generics,
as,satisfies,!. Not erasable:enum, runtimenamespace, and constructor parameter properties (constructor(private x: number)). - No
tsconfig.jsonis read. Options such aspathsandjsxare ignored, and.tsxis not supported. - Module format follows the same rules as JavaScript:
.mtsis ES module,.ctsis CommonJS,.tsfollows the"type"field inpackage.json. - Not for packages in
node_modules. Publish JavaScript (plus.d.tsfiles) from libraries. - Warnings:
--experimental-transform-typesprints anExperimentalWarning; stripping alone does not in current releases. Quieten with--disable-warning. - Version notes: introduced in Node.js 22.6 behind the flag, enabled by default from 22.18 and 23.6; transform mode arrived in 22.7.