AZ.dev

Run a TypeScript file with node and no build step

| node: 22.18+ / 24

Current Node runs .ts files by stripping the type annotations. No flag, no loader.

node app.ts

Type stripping is on by default in Node 22.18 and every 24 release. Node 22.6 to 22.17 need the flag:

node --experimental-strip-types app.ts

What it doesn’t do

Stripping removes annotations and does no type checking and no rewriting. Syntax that needs a real transform is rejected unless you add --experimental-transform-types:

tsconfig.json is ignored entirely, so paths aliases don’t resolve and imports need the file extension, as ESM always did: import { a } from "./a.ts". Write the extension as .ts, not .js; the stripped file is served under its real name.

When to use tsx instead

tsx (the npm package) handles enums, path aliases and CommonJS interop, and works on any Node version. Use it for a project that already relies on those, and for scripts that have to run on older Node in CI.

npx tsx scripts/task.ts

For a new script with plain ESM and types only, bare node is enough and one dependency fewer.

Gotchas

typescript strip-types node esm tsx

This entry is one card on a printable cheat sheet:

Node.js Essentials Cheat Sheet

Was this helpful?

Related Entries

Reproduce Railway's npm ci locally with the exact npm versionSerialize per-user check-then-write flows with pg_advisory_xact_lock(hashtext(id))Content-hash dedup that restores a soft-deleted row must re-run quota and limit checksA storage URL builder and its static file handler must share one prefix constantGive a fetch call a timeout