Running TypeScript directly in Node

This month, Node 24.12 and 25.2 marked type stripping as stable. That means you can run a .ts file with plain node, no flag, no ts-node, no build step:

This month, Node 24.12 and 25.2 marked type stripping as stable. That means you can run a .ts file with plain node, no flag, no ts-node, no build step:

node src/main.ts

It took a while to get here. Type stripping arrived behind a flag in Node 22.6 in August 2024, was turned on by default in 23.6, stopped printing an experimental warning in 24.3, and is now stable.

What it does, and doesn’t do

Node doesn’t compile your TypeScript. It removes the type annotations, replacing them with whitespace, and runs what’s left as JavaScript. Because it only blanks things out, line and column numbers stay the same and you don’t need source maps.

It also means there’s no type checking. This runs without complaint:

const n: number = 'not a number';
console.log(n); // not a number

So node runs your code and tsc —noEmit checks it. Keep the type check in your editor, your CI, or a pre-commit hook.

A small example

// src/user.ts
export interface User {
  id: number;
  name: string;
  email?: string;
}

export function formatUser(user: User): string {
  return user.email ? `${user.name} <${user.email}>` : user.name;
}
// src/main.ts
import { formatUser, type User } from './user.ts';

const users: User[] = [
  { id: 1, name: 'Asha', email: 'asha@example.com' },
  { id: 2, name: 'Ravi' },
];

for (const user of users) {
  console.log(formatUser(user));
}

Two things in that import matter.

The .ts extension is required. Node resolves files exactly as written, and it doesn’t guess. import ’./user’ fails with ERR_MODULE_NOT_FOUND.

Type-only imports need type. Node strips each file on its own, without looking at other files, so it can’t know that User is only a type. Without the type keyword it keeps the import, and you get this at runtime:

SyntaxError: The requested module './user.ts' does not provide an export named 'User'

Syntax that needs real compilation

Some TypeScript features generate JavaScript code instead of just being removed. Those don’t work:

enum Role {
  Admin = 'admin',
  Viewer = 'viewer',
}
// SyntaxError [ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX]:
// TypeScript enum is not supported in strip-only mode

The same goes for parameter properties (constructor(private url: string)), namespaces that contain code, and the old import x = require() syntax. There’s an —experimental-transform-types flag that handles them, but I’d rather change the code. For enums, a plain object does the same job:

export const Role = {
  Admin: 'admin',
  Viewer: 'viewer',
} as const;

export type Role = (typeof Role)[keyof typeof Role];

Decorators aren’t supported either, which rules out NestJS and similar frameworks for now.

A tsconfig that matches

Node ignores tsconfig.json completely. That includes paths aliases, which won’t resolve. Your config still matters for tsc and your editor, though, and a few options make TypeScript catch the problems above before Node does:

{
  "compilerOptions": {
    "noEmit": true,
    "target": "esnext",
    "module": "nodenext",
    "rewriteRelativeImportExtensions": true,
    "erasableSyntaxOnly": true,
    "verbatimModuleSyntax": true
  }
}

erasableSyntaxOnly (TypeScript 5.8) turns enums and parameter properties into type errors. verbatimModuleSyntax makes you write import type where it’s needed. rewriteRelativeImportExtensions lets you write .ts in imports and still emit correct .js imports if you build a package later.

Where it fits

Scripts, CLIs, tests and small services are where this shines. There’s no dist folder, no watch-and-compile step, and stack traces point at your real files. node —watch src/main.ts gives you a dev loop with no tooling at all.

For libraries you publish, keep compiling to JavaScript. Node refuses to strip types inside node_modules, on purpose, so packages still need to ship .js files. And .tsx isn’t supported, so frontend code still goes through a bundler.