πŸ”§ Error Fixes
Β· 2 min read
Last updated on

Turborepo: Cache Miss β€” Tasks Running When They Shouldn't


cache miss, executing task

What causes this

Turborepo’s whole point is caching β€” if inputs haven’t changed, skip the task. When you see β€œcache miss” on every run, something is invalidating the cache between runs. Common causes:

  • The outputs field in turbo.json is wrong or missing, so Turborepo can’t store results
  • Untracked files are changing between runs (generated files, timestamps, etc.)
  • Environment variables are changing and Turborepo detects them as input changes
  • You’re running in CI without a remote cache configured

Fix 1: Check your outputs configuration

Turborepo needs to know what files your task produces so it can cache them:

{
  "tasks": {
    "build": {
      "outputs": ["dist/**", ".next/**", "build/**"],
      "dependsOn": ["^build"]
    },
    "lint": {
      "outputs": []
    }
  }
}

If outputs is missing or wrong, Turborepo can’t restore cached results. Tasks that don’t produce files (like lint or test) should have "outputs": [].

Fix 2: Pin your inputs

By default, Turborepo hashes all files in a package to determine if it changed. If generated files or logs change between runs, you get cache misses. Be explicit about inputs:

{
  "tasks": {
    "build": {
      "inputs": ["src/**", "package.json", "tsconfig.json"],
      "outputs": ["dist/**"]
    }
  }
}

This tells Turborepo to only look at source files, not generated output or temp files.

Fix 3: Declare environment variables

Turborepo detects environment variable changes. If a variable changes between runs (like BUILD_TIME or CI_COMMIT_SHA), the cache is invalidated:

{
  "globalEnv": ["NODE_ENV"],
  "tasks": {
    "build": {
      "env": ["API_URL", "DATABASE_URL"]
    }
  }
}

Variables not listed in env or globalEnv are ignored for cache purposes. Only list the ones that actually affect your build output.

Fix 4: Debug the cache

Use --summarize to see exactly why a cache miss happened:

npx turbo build --summarize

This generates a JSON summary showing what changed. You can also use:

# See the hash for each task
npx turbo build --dry-run=json

Fix 5: Set up remote caching in CI

Without remote caching, CI always starts fresh:

# Using Vercel Remote Cache
npx turbo login
npx turbo link

Or self-host with a custom cache server by setting TURBO_API, TURBO_TOKEN, and TURBO_TEAM environment variables in your CI pipeline.

How to prevent it

  • Always define outputs for every task in turbo.json
  • Use explicit inputs for tasks that are sensitive to file changes
  • Declare all build-affecting environment variables in env or globalEnv
  • Set up remote caching early β€” it’s the biggest time saver in CI
  • Run turbo build --summarize periodically to catch unexpected cache invalidations

Related: npm vs pnpm vs yarn Β· What is a Monorepo? Β· GitHub Actions cheat sheet