Skip to content
Tutorials Center
My learning

Topics

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.

NODE
// shell: node app.ts

Try it

Node.js Running a TypeScript file

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.

Node.js Limits of stripping

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

NODE
// 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. In tsconfig.json, enable allowImportingTsExtensions and rewriteRelativeImportExtensions (or erasableSyntaxOnly) so the compiler agrees.
  • Type-only imports need import type (or import { 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, runtime namespace, and constructor parameter properties (constructor(private x: number)).
  • No tsconfig.json is read. Options such as paths and jsx are ignored, and .tsx is not supported.
  • Module format follows the same rules as JavaScript: .mts is ES module, .cts is CommonJS, .ts follows the "type" field in package.json.
  • Not for packages in node_modules. Publish JavaScript (plus .d.ts files) from libraries.
  • Warnings: --experimental-transform-types prints an ExperimentalWarning; 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.