// Blog

Can Node.js run your TypeScript without a build step?

Can Node.js run TypeScript files without a compiler? Yes. On current Node.js releases, node server.ts just works: no ts-node, no loader, no dist folder. TypeScript is JavaScript with type annotations, and until recently every TypeScript project needed a compile step before Node.js could run it.

The catch is in how it works. Node.js removes the type annotations and runs what is left. It does not check your types, it does not read tsconfig.json, and it refuses TypeScript syntax that would have to be rewritten into different JavaScript, including the decorators that NestJS is built on.

Our short answer: drop the build step for scripts, tooling and small new services. Keep it for NestJS APIs and for packages you publish. In both cases, let the TypeScript compiler do the type checking in continuous integration (CI), the automated checks that run on every change. TypeScript 7 has made that check fast enough that there is no reason to skip it.

What Node.js does with a .ts file

The feature is called type stripping. According to the Node.js TypeScript documentation, Node.js replaces TypeScript syntax with whitespace and performs no type checking. Because the types become blank space rather than being removed, line and column numbers stay the same, so stack traces point at your real source lines and no source maps are needed.

It has been a gradual rollout. Type stripping arrived behind a flag in Node.js 22.6, was switched on by default in 23.6 and 22.18, and was marked stable in 24.12 and 25.2. Node.js 26 removed the older --experimental-transform-types flag, which had handled some of the extra syntax. If you run Node.js 24.12 or newer, including 26, this is a stable, default-on feature, and --no-strip-types turns it off.

What it will not run

Type stripping only works for "erasable" syntax: TypeScript that disappears cleanly and leaves valid JavaScript behind. The Node.js docs list what falls outside that:

  • Enums, namespaces with runtime code, parameter properties and import aliases. These need code generation, so Node.js throws ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX.
  • Decorators. They cause a parser error. Node.js will not support them until JavaScript itself does.
  • Anything that depends on tsconfig.json. Path aliases are not resolved and newer syntax is not converted for older runtimes.
  • .tsx files. They are not supported at all.
  • TypeScript inside node_modules. Node.js deliberately refuses it, to discourage publishing packages as raw TypeScript.
  • Type imports without the type keyword. Node.js treats them as value imports, which fails at runtime.

Two more habits change. Relative imports need the real file extension, ./greet.ts rather than ./greet. And whether a .ts file runs as an ES module or CommonJS follows the same rules as .js, so "type": "module" in package.json still decides it.

A minimal setup that works

This is the setup we use for a small service or a set of scripts. It runs on Node.js 24.12 or newer, including 26, with TypeScript 5.8 or newer, including 7. The compiler options are the ones the Node.js docs recommend, plus types and include.

{
  "compilerOptions": {
    "noEmit": true,
    "target": "esnext",
    "module": "nodenext",
    "rewriteRelativeImportExtensions": true,
    "erasableSyntaxOnly": true,
    "verbatimModuleSyntax": true,
    "types": ["node"]
  },
  "include": ["src"]
}

The important line is erasableSyntaxOnly. TypeScript 5.8 added it so that the compiler flags enums, parameter properties and the rest while you are writing them, instead of you finding out when Node.js refuses to start. verbatimModuleSyntax does the same for type imports that are missing the type keyword. The types entry needs @types/node installed, and on TypeScript 7 it is required, as we explain below.

rewriteRelativeImportExtensions is what lets you write ./greet.ts in an import. The TSConfig reference says that turning it on also turns on allowImportingTsExtensions by default, so tsc type-checks imports that end in .ts. If you later drop noEmit and emit JavaScript, the same option, added in TypeScript 5.7, rewrites those relative imports to .js in the output.

{
  "type": "module",
  "scripts": {
    "start": "node src/server.ts",
    "dev": "node --watch src/server.ts",
    "typecheck": "tsc"
  }
}

Two source files are enough to see it all work:

// src/greet.ts
export type Greeting = { message: string };

export function greet(name: string): Greeting {
  return { message: "Hello, " + name };
}
// src/server.ts
import { createServer } from "node:http";
import { greet, type Greeting } from "./greet.ts";

const server = createServer((req, res) => {
  const body: Greeting = greet("Žilina");
  res.writeHead(200, { "content-type": "application/json" });
  res.end(JSON.stringify(body));
});

server.listen(3000);

npm run dev restarts the server when a file changes, using Node's built-in --watch mode. npm run typecheck is the only place types are actually checked.

Replacing enums and parameter properties

The two constructs that come up most often have plain equivalents. An enum becomes a constant object plus a type with the same name, and a parameter property becomes an ordinary field.

export const Status = { Draft: "draft", Published: "published" } as const;
export type Status = (typeof Status)[keyof typeof Status];

type Db = { query(sql: string): Promise<unknown[]> };

export class EventRepository {
  private db: Db;

  constructor(db: Db) {
    this.db = db;
  }
}

It is a little more typing. In our opinion it also reads more like the JavaScript that actually runs, which helps anyone debugging it later.

Type checking moves to CI, and TypeScript 7 makes it cheap

When Node.js runs your code directly, a type error no longer stops anything. The app starts, and the mistake shows up when that line runs. So the compiler's job changes from "build the app" to "check the app", and that check has to run on every pull request, before anything is deployed.

The timing works out well. TypeScript 7 was released on 8 July 2026 as a native port of the compiler written in Go. Microsoft reports full-build speedups typically between 8x and 12x, and in its own measurements the VS Code codebase went from 125.7 seconds on TypeScript 6 to 10.6 seconds. A check that took minutes is now short enough that nobody is tempted to skip it.

The upgrade is not just a version bump, because TypeScript 7 adopts the new defaults from 6.0 and turns its deprecations into errors. The changes most likely to affect a Node.js project:

  • types now defaults to an empty list. Node's globals vanish unless you list "node", which is why it is in the config above.
  • strict is on by default. Older projects that never enabled it will see new errors.
  • baseUrl and moduleResolution: node10 are gone. Use nodenext or bundler, and make paths relative to the project root.
  • rootDir defaults to the folder containing tsconfig.json. Set it explicitly if you emit from src.
  • TypeScript 7.0 has no programmatic API yet. Tools that import the compiler, such as typescript-eslint, need TypeScript 6 installed alongside it. Microsoft publishes @typescript/typescript6 for exactly that, with npm alias examples in the announcement.

On small CI runners it is worth knowing about the new --checkers flag. TypeScript 7 runs four type-checking workers by default, and fewer can be better on a machine with few cores and little memory.

Where we use it, and where we do not

Most of our client work is TypeScript end to end: NestJS APIs, React PWAs and Expo mobile apps. Type stripping fits some of that and not the rest.

ProjectRun .ts directly?Why
Scripts, seeds, migrations, CLIsYesThe biggest win. No ts-node and no build just to run a one-off task.
Small new services and workersYesIf they are written with erasable syntax from day one.
NestJS APIsNoNest is built around decorators, and its dependency injection examples use parameter properties. Keep the build, upgrade the compiler.
React PWAs, Expo appsNot relevantThe bundler compiles the code anyway, and Node.js does not run .tsx.
Packages you publish to npmNoNode.js will not strip types inside node_modules, so ship JavaScript and type declarations.

For teams that need full TypeScript at runtime, decorators included, the Node.js docs point to third-party runners such as tsx. We prefer to keep it simple: native stripping where it fits, a normal build where it does not.

Moving an existing project over

For a codebase that is not built on decorators, the move is mostly mechanical. The order we follow:

  1. Upgrade to Node.js 24.12 or newer.
  2. Turn on erasableSyntaxOnly and verbatimModuleSyntax, run tsc, and fix what it reports. This list is your real migration scope.
  3. Add .ts extensions to relative imports. With rewriteRelativeImportExtensions on, the compiler accepts them, and rewrites them to .js if you still emit output.
  4. Replace paths aliases with Node's subpath imports, which must start with #.
  5. Point the start scripts at the .ts files, remove the old loader, and make tsc a required CI step.
  6. Run the full test suite against the stripped code, not a compiled copy.

What to do next

If your Node.js scripts or small services still go through a build step only so they can run, that step can probably go. Start with one internal script, turn on erasableSyntaxOnly, and see what the compiler says. For NestJS APIs, leave the build alone and look at TypeScript 7 instead, because faster checks help every developer on the team.

Either way, keep tsc in CI. Running TypeScript without checking it is just JavaScript with extra steps.

If you are planning a Node.js backend or want a second opinion on an existing TypeScript setup, tell us about it. We are happy to talk it through.