Build System Overview
TypeScript uses hereby, a modern task runner, to orchestrate its build process. The build is defined inHerebyfile.mjs and compiles TypeScript source code using itself (bootstrapping).
Quick Build
To build the entire compiler and services:- 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:built/local/tsc.js
Language Services
Build the TypeScript API library:built/local/typescript.js
Language Server
Build the tsserver for editor integration:built/local/tsserver.js
Minimal Build
Build onlytsc and tsserver (fastest):
Build Configuration
Bundle Mode (Default)
By default, hereby uses esbuild to create bundled outputs:- Faster execution (single file)
- Smaller output size
- Production-like builds
Unbundled Mode
For development with better source mapping:- Easier debugging
- Faster incremental builds
- Better stack traces
Skip Type Checking
Speed up builds by skipping type checking:Available Build Tasks
- Primary Tasks
- Utility Tasks
- Advanced Tasks
Watch Mode
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.jswith cache enablementbuilt/local/tsserver.js→ wraps_tsserver.jswith cache enablementbuilt/local/typingsInstaller.js→ wraps_typingsInstaller.js
Library Files
TypeScript’s standard library definitions are built from sources:src/lib/*.d.tsOutputs:
built/local/lib.*.d.ts
The src/lib/libs.json file defines which libraries are built and their output names.
Last Known Good (LKG)
The LKG is a stable compiler snapshot used to bootstrap builds:built/local/* to lib/, replacing the bootstrap compiler.
Diagnostic Messages
TypeScript’s error messages are defined in JSON:src/compiler/diagnosticMessages.jsonOutputs:
src/compiler/diagnosticInformationMap.generated.tssrc/compiler/diagnosticMessages.generated.json
Troubleshooting
Build fails with 'hereby: command not found'
Build fails with 'hereby: command not found'
Install hereby globally:
Out of memory during build
Out of memory during build
Increase Node.js memory:
Build is very slow
Build is very slow
Try these optimizations:
- Use
hereby mininstead ofhereby local - Add
--no-typecheckfor faster iteration - Use
--bundle=true(default) for faster execution - Close other applications to free memory
Changes not reflected in build
Changes not reflected in build
Clean and rebuild:
LKG task fails with missing files
LKG task fails with missing files
The LKG task requires bundle mode:
NPM Scripts
Alternatively, use npm scripts defined inpackage.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