Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Configure and optimize Turborepo monorepo build pipelines with correct task structure, caching, and CI setup.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/caching/gotchas.md
1# Debugging Cache Issues23## Diagnostic Tools45### `--summarize`67Generates a JSON file with all hash inputs. Compare two runs to find differences.89```bash10turbo build --summarize11# Creates .turbo/runs/<run-id>.json12```1314The summary includes:1516- Global hash and its inputs17- Per-task hashes and their inputs18- Environment variables that affected the hash1920**Comparing runs:**2122```bash23# Run twice, compare the summaries24diff .turbo/runs/<first-run>.json .turbo/runs/<second-run>.json25```2627### `--dry` / `--dry=json`2829See what would run without executing anything:3031```bash32turbo build --dry33turbo build --dry=json # machine-readable output34```3536Shows cache status for each task without running them.3738### `--force`3940Skip reading cache, re-execute all tasks:4142```bash43turbo build --force44```4546Useful to verify tasks actually work (not just cached results).4748## Unexpected Cache Misses4950**Symptom:** Task runs when you expected a cache hit.5152### Environment Variable Changed5354Check if an env var in the `env` key changed:5556```json57{58"tasks": {59"build": {60"env": ["API_URL", "NODE_ENV"]61}62}63}64```6566Different `API_URL` between runs = cache miss.6768### .env File Changed6970`.env` files aren't tracked by default. Add to `inputs`:7172```json73{74"tasks": {75"build": {76"inputs": ["$TURBO_DEFAULT$", ".env", ".env.local"]77}78}79}80```8182Or use `globalDependencies` for repo-wide env files:8384```json85{86"globalDependencies": [".env"]87}88```8990With `futureFlags.globalConfiguration`, use `global.inputs` instead. The key difference: `global.inputs` files are folded into each task's hash individually (not the global hash), so tasks can exclude specific files with negation globs.9192```json93{94"futureFlags": { "globalConfiguration": true },95"global": {96"inputs": [".env"]97}98}99```100101### Lockfile Changed102103Installing/updating packages changes the global hash.104105### Source Files Changed106107Any file in the package (or in `inputs`) triggers a miss.108109### turbo.json Changed110111Config changes invalidate the global hash.112113## Incorrect Cache Hits114115**Symptom:** Cached output is stale/wrong.116117### Missing Environment Variable118119Task uses an env var not listed in `env`:120121```javascript122// build.js123const apiUrl = process.env.API_URL; // not tracked!124```125126Fix: add to task config:127128```json129{130"tasks": {131"build": {132"env": ["API_URL"]133}134}135}136```137138### Missing File in Inputs139140Task reads a file outside default inputs:141142```json143{144"tasks": {145"build": {146"inputs": [147"$TURBO_DEFAULT$",148"../../shared-config.json" // file outside package149]150}151}152}153```154155## Useful Flags156157```bash158# Only show output for cache misses159turbo build --output-logs=new-only160161# Show output for everything (debugging)162turbo build --output-logs=full163164# See why tasks are running165turbo build --verbosity=2166```167168## Debugging with `globalConfiguration` Enabled169170When `futureFlags.globalConfiguration` is on, `global.inputs` files appear in per-task hash inputs (not the global hash). If you're getting unexpected cache misses:1711721. Check `--summarize` output — global input files will show up in the **task inputs** section, not the global hash section1732. Verify tasks aren't accidentally excluding global inputs via negation globs in `inputs`1743. Remember that toggling the `globalConfiguration` flag itself invalidates all caches (the flag value is part of the global hash)175176If you're getting unexpected cache **hits** after changing a global input file, the task may be excluding that file with a negation glob. Check the task's `inputs` for `!$TURBO_ROOT$/...` patterns.177178## Quick Checklist179180Cache miss when expected hit:1811821. Run with `--summarize`, compare with previous run1832. Check env vars with `--dry=json`1843. Look for lockfile/config changes in git185186Cache hit when expected miss:1871881. Verify env var is in `env` array1892. Verify file is in `inputs` array1903. Check if file is outside package directory191