Skip to main content

Build System Overview

TypeScript uses hereby, a modern task runner, to orchestrate its build process. The build is defined in Herebyfile.mjs and compiles TypeScript source code using itself (bootstrapping).

Quick Build

To build the entire compiler and services:
This command:
  • Generates diagnostic messages from src/compiler/diagnosticMessages.json
  • Builds the compiler (tsc)
  • Builds the language service server (tsserver)
  • Builds the TypeScript library (typescript.js)
  • Generates library definition files (lib.*.d.ts)
  • Creates type definition bundles (typescript.d.ts)
The first build takes several minutes. Subsequent builds are faster due to incremental compilation.

Common Build Tasks

Compiler Only

Build just the command-line compiler:
Output: built/local/tsc.js

Language Services

Build the TypeScript API library:
Output: built/local/typescript.js

Language Server

Build the tsserver for editor integration:
Output: built/local/tsserver.js

Minimal Build

Build only tsc and tsserver (fastest):

Build Configuration

Bundle Mode (Default)

By default, hereby uses esbuild to create bundled outputs:
Advantages:
  • Faster execution (single file)
  • Smaller output size
  • Production-like builds

Unbundled Mode

For development with better source mapping:
Advantages:
  • Easier debugging
  • Faster incremental builds
  • Better stack traces
Some tasks like LKG require bundle mode and will fail if --bundle=false is set.

Skip Type Checking

Speed up builds by skipping type checking:
Use --no-typecheck during rapid iteration, but always run a full build before submitting PRs.

Available Build Tasks

View all available tasks:

Watch Mode

Watch mode is experimental and may not work as expected. Use at your own risk.
Automatically rebuild on file changes:

Build Outputs

Directory Structure

Compile Cache Optimization

Node.js 23+ uses module compilation caching. TypeScript generates shim files for:
  • built/local/tsc.js → wraps _tsc.js with cache enablement
  • built/local/tsserver.js → wraps _tsserver.js with cache enablement
  • built/local/typingsInstaller.js → wraps _typingsInstaller.js
This improves startup performance on supported Node versions.

Library Files

TypeScript’s standard library definitions are built from sources:
Sources: src/lib/*.d.ts
Outputs: built/local/lib.*.d.ts
The src/lib/libs.json file defines which libraries are built and their output names.
src/lib/dom.generated.d.ts and src/lib/webworker.generated.d.ts are auto-generated. To modify them, contribute to TSJS-lib-generator.

Last Known Good (LKG)

The LKG is a stable compiler snapshot used to bootstrap builds:
This copies built/local/* to lib/, replacing the bootstrap compiler.
Only run this command when the built compiler is stable! A broken LKG prevents building from source.

Diagnostic Messages

TypeScript’s error messages are defined in JSON:
Input: src/compiler/diagnosticMessages.json
Outputs:
  • src/compiler/diagnosticInformationMap.generated.ts
  • src/compiler/diagnosticMessages.generated.json
After modifying diagnostic messages, always run this task before building.

Troubleshooting

Install hereby globally:
Increase Node.js memory:
Try these optimizations:
  • Use hereby min instead of hereby local
  • Add --no-typecheck for faster iteration
  • Use --bundle=true (default) for faster execution
  • Close other applications to free memory
Clean and rebuild:
The LKG task requires bundle mode:

NPM Scripts

Alternatively, use npm scripts defined in package.json:
The npm scripts are wrappers around hereby tasks. Using hereby directly provides more options.

Next Steps

Testing

Learn how to run and write tests

Debugging

Debug the compiler and language service