How to fix Project reference is stale, run 'tsc --build' in TypeScript

TypeScriptINTERMEDIATEMEDIUMUpdated Dec 11, 2025ยท 164 views

This TypeScript error occurs when using project references and the referenced project has been modified without rebuilding. TypeScript needs to rebuild the referenced project to ensure type information is up-to-date. Running `tsc --build` or `tsc -b` will rebuild all referenced projects.

Quick fix

Fixes Project reference is stale, run 'tsc --build'

# Rebuild all projects in the solution
tsc --build

# Or with shorter syntax
tsc -b

# If you have a specific tsconfig.json for building
tsc --build tsconfig.json

# For incremental builds (faster)
tsc --build --incremental
  1. Run tsc --build to rebuild all projects
  2. Clean and rebuild if issues persist
  3. Configure proper project references in tsconfig.json
  4. Set up build scripts in package.json
typescript โ€” error
# Rebuild all projects in the solution
tsc --build
# Or with shorter syntax
tsc -b
# If you have a specific tsconfig.json for building
tsc --build tsconfig.json
# For incremental builds (faster)
tsc --build --incremental
Project reference is stale, run 'tsc --build'

What this error means

The "Project reference is stale" error appears when you're using TypeScript's project references feature and a referenced project has changed since it was last built. TypeScript project references allow you to structure large codebases into multiple TypeScript projects that depend on each other. When Project A references Project B, TypeScript needs to know the compiled output and type information from Project B. If you modify files in Project B but don't rebuild it, Project A will see outdated type information, leading to this error. This is a safety feature that ensures type consistency across your entire codebase. TypeScript detects when referenced projects have been modified and requires a rebuild before continuing compilation.

Typical symptoms

  • Compilation fails with "Project reference is stale, run tsc --build" error
  • Error occurs after modifying files in a referenced TypeScript project
  • TypeScript server in IDE shows errors for imports from referenced projects
  • Build process works initially but fails after making changes to dependencies
  • Error appears even when the modified files seem unrelated to the current project

Common causes

  1. Modified source files in a referenced TypeScript project without rebuilding
  2. Deleted or renamed files in a referenced project
  3. Changed tsconfig.json settings in a referenced project
  4. Using `tsc` instead of `tsc --build` to compile projects with references
  5. Outdated .tsbuildinfo files from previous builds
  6. Manual editing of compiled output files (.d.ts, .js) instead of source files

How to fix "Project reference is stale, run 'tsc --build'"

1Run tsc --build to rebuild all projects

The simplest fix is to run tsc --build (or tsc -b) from the root of your project:

bash
# Rebuild all projects in the solution
tsc --build

# Or with shorter syntax
tsc -b

# If you have a specific tsconfig.json for building
tsc --build tsconfig.json

# For incremental builds (faster)
tsc --build --incremental

The --build flag tells TypeScript to:
1. Detect all project references
2. Build them in the correct dependency order
3. Update .tsbuildinfo files to track build state
4. Ensure type consistency across all projects

After running this command, try compiling your main project again.

2Clean and rebuild if issues persist

If tsc --build doesn't resolve the issue, try cleaning the build artifacts first:

bash
# Clean all build outputs
tsc --build --clean

# Then rebuild
tsc --build

# Or combine in one command
tsc --build --clean --force

This removes:
- Compiled .js and .d.ts files
- .tsbuildinfo files
- Any cached build information

After cleaning, TypeScript will perform a fresh build of all projects.

3Configure proper project references in tsconfig.json

Ensure your tsconfig.json files have correct project references configuration:

json
// tsconfig.json (root or main project)
{
  "compilerOptions": {
    "composite": true,
    "declaration": true,
    "declarationMap": true,
    "outDir": "./dist"
  },
  "references": [
    { "path": "./packages/core" },
    { "path": "./packages/utils" }
  ]
}

// packages/core/tsconfig.json
{
  "compilerOptions": {
    "composite": true,
    "declaration": true,
    "declarationMap": true,
    "outDir": "../../dist/core"
  }
}

// packages/utils/tsconfig.json
{
  "compilerOptions": {
    "composite": true,
    "declaration": true,
    "declarationMap": true,
    "outDir": "../../dist/utils"
  }
}

Key requirements:
- All referenced projects must have "composite": true
- All referenced projects must have "declaration": true
- Output directories should not overlap
- References use relative paths to project directories

4Set up build scripts in package.json

Create proper build scripts to avoid manual tsc --build commands:

json
// package.json
{
  "scripts": {
    "build": "tsc --build",
    "build:clean": "tsc --build --clean",
    "build:watch": "tsc --build --watch",
    "build:incremental": "tsc --build --incremental",
    "clean": "tsc --build --clean"
  }
}

Then use:

bash
npm run build        # Standard build
npm run build:watch  # Watch mode for development
npm run clean        # Clean build artifacts

For monorepos with multiple packages:

json
{
  "scripts": {
    "build": "npm run build --workspaces",
    "build:packages": "npm run build --workspace=packages/*"
  }
}
5Check for common configuration issues

Verify these common configuration problems:

1. Missing composite flag:

json
// WRONG - missing composite
{
  "compilerOptions": {
    "declaration": true
  }
}

// CORRECT
{
  "compilerOptions": {
    "composite": true,
    "declaration": true
  }
}

2. Overlapping output directories:

json
// WRONG - projects output to same directory
{
  "compilerOptions": {
    "outDir": "../dist"
  }
}

// CORRECT - unique output directories
{
  "compilerOptions": {
    "outDir": "../dist/core"
  }
}

3. Incorrect reference paths:

json
// WRONG - references tsconfig.json file directly
{
  "references": [
    { "path": "./packages/core/tsconfig.json" }
  ]
}

// CORRECT - references directory
{
  "references": [
    { "path": "./packages/core" }
  ]
}

4. Missing declaration files:
- Ensure "declaration": true is set
- Check that .d.ts files are being generated
- Verify .d.ts files are in the correct output directory

6Use watch mode for development

During development, use watch mode to automatically rebuild when files change:

bash
# Watch all projects
tsc --build --watch

# Watch with specific tsconfig
tsc --build tsconfig.json --watch

# Watch with incremental builds
tsc --build --watch --incremental

# In package.json scripts
{
  "scripts": {
    "dev": "tsc --build --watch",
    "dev:incremental": "tsc --build --watch --incremental"
  }
}

Watch mode benefits:
- Automatically rebuilds when any source file changes
- Maintains correct build order across projects
- Shows compilation errors in real-time
- Faster than manual builds with incremental compilation

For CI/CD pipelines, ensure you run tsc --build before any type checking or testing.

Advanced notes

### Understanding .tsbuildinfo Files

TypeScript uses .tsbuildinfo files to track build state for composite projects. These files contain:
- Timestamps of source files
- Compiler options used
- Dependency graph between files
- Build signatures for incremental compilation

When you modify a source file, TypeScript compares its timestamp against the .tsbuildinfo file. If they don't match, the project is marked as "stale".

### Solution Reference Mode vs Build Mode

TypeScript has two modes for project references:

Solution Reference Mode (default with tsc):
- Only type-checks projects
- Assumes referenced projects are already built
- Fails with "stale" error if referenced projects changed

Build Mode (tsc --build):
- Builds projects in dependency order
- Updates .tsbuildinfo files
- Handles stale references automatically
- Required for composite projects

### Common Pitfalls

1. Mixed build tools: Using both tsc --build and other build tools (webpack, esbuild) can cause conflicts. Ensure all tools use the same build artifacts.

2. Git operations: Git operations that modify timestamps (checkout, reset) can trigger stale errors. Run tsc --build after such operations.

3. IDE integration: Some IDEs may run tsc instead of tsc --build. Configure your IDE to use build mode:
- VS Code: Set "typescript.tsdk" and use Build Task
- WebStorm: Configure TypeScript compiler with --build flag

4. Monorepo tools: If using Lerna, Nx, or Turborepo, ensure they call tsc --build not tsc.

### Performance Considerations

- Incremental builds: Use --incremental flag for faster rebuilds
- Parallel builds: TypeScript builds projects in parallel when possible
- Memory usage: Large projects may need increased Node.js memory limit: NODE_OPTIONS=--max-old-space-size=4096

### Debugging

To debug project reference issues:

bash
# Verbose output showing build steps
tsc --build --verbose

# List all project references
tsc --build --dry

# Show dependency graph
tsc --build --listFiles

# Check specific project
tsc --project packages/core --showConfig

Frequently asked questions

What does "Project reference is stale, run 'tsc --build'" mean?
The "Project reference is stale" error appears when you're using TypeScript's project references feature and a referenced project has changed since it was last built. TypeScript project references allow you to structure large codebases into multiple TypeScript projects that depend on each other. When Project A references Project B, TypeScript needs to know the compiled output and type information from Project B.
How do I fix "Project reference is stale, run 'tsc --build'"?
This TypeScript error occurs when using project references and the referenced project has been modified without rebuilding. TypeScript needs to rebuild the referenced project to ensure type information is up-to-date. Running tsc --build or tsc -b will rebuild all referenced projects.
What causes "Project reference is stale, run 'tsc --build'"?
Modified source files in a referenced TypeScript project without rebuilding Deleted or renamed files in a referenced project Changed tsconfig.json settings in a referenced project
Is the "Project reference is stale, run 'tsc --build'" error serious?
It is a medium-severity error โ€” more of a blocker than a risk. The steps above resolve it.

Official resources & further reading