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
outputsfield inturbo.jsonis 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
outputsfor every task inturbo.json - Use explicit
inputsfor tasks that are sensitive to file changes - Declare all build-affecting environment variables in
envorglobalEnv - Set up remote caching early β itβs the biggest time saver in CI
- Run
turbo build --summarizeperiodically to catch unexpected cache invalidations
Related: npm vs pnpm vs yarn Β· What is a Monorepo? Β· GitHub Actions cheat sheet