Common Turborepo cache issues and recovery procedures.
- Tasks fail with cryptic errors
- "cache hit" but outputs are missing or incorrect
- Inconsistent behavior between runs
# Run task twice - should be identical
pnpm build
pnpm build
# If second run shows different results, cache may be corrupted- Interrupted build process
- Disk corruption
- Manual modification of cached files
- Bug in Turborepo (rare)
# Remove cache directory
rm -rf .turbo
# Force rebuild
pnpm build --force# Use justfile command
just clean
# Or manually
rm -rf .turbo
rm -rf node_modules/.cache
rm -rf .venv
uv sync --all-packages
pnpm install# Run build twice
pnpm build
pnpm build
# Second run should show "cache hit"- Don't manually modify
.turbo/directory - Ensure adequate disk space
- Let tasks complete fully
- Use
--forcewhen testing cache behavior
Tasks: 4 successful, 4 total
Cached: 0 cached, 4 total # Expected some cache hits
Time: 2.5s
// turbo.json
{
"tasks": {
"build": {
"inputs": ["src/**", "pyproject.toml"] # These files affect cache
}
}
}Common issues:
- Missing files in
inputs - Too broad glob patterns
- Generated files in inputs
# Check git status
git status
# Check for generated files
find . -name "*.pyc" -o -name "__pycache__"# View turbo configuration
cat turbo.json
# Check cache location
ls -la .turbo/cache/# See why cache missed
pnpm build --verbosity=2// Bad - includes generated files
{
"inputs": ["**/*.py"] // Includes __pycache__/*.pyc
}
// Good - excludes generated files
{
"inputs": ["src/**/*.py", "tests/**/*.py", "pyproject.toml"]
}// Bad - missing config file
{
"inputs": ["src/**"]
}
// Good - includes config
{
"inputs": ["src/**", "pyproject.toml", ".ruff.toml"]
}Files modified but content unchanged still trigger cache miss.
Solution: Ensure clean working directory
git status # Should be clean- Builds take longer than expected
- Cache hits but still slow
- "FULL TURBO" but not fast
pnpm build
# Look for:
# Cached: X cached, Y total
# Should be high percentage on unchanged code# Run with timing
time pnpm build
# Check individual task times in output# Look for tasks that always run
pnpm build --verbosity=2// turbo.json
{
"tasks": {
"lint": {
"cache": true,
"inputs": [
"**/*.py", // Only Python files
"pyproject.toml", // Config
".ruff.toml" // Ruff config
]
// Don't include: tests/, docs/, etc.
}
}
}{
"tasks": {
"lint": {
"cache": true
// No dependsOn - runs in parallel
},
"test": {
"cache": true,
"dependsOn": ["^build"] // Only depends on build
}
}
}// Bad - unnecessary dependency
{
"test": {
"dependsOn": ["lint", "format", "^build"] // Too many deps
}
}
// Good - minimal dependencies
{
"test": {
"dependsOn": ["^build"] // Only what's needed
}
}{
"build": {
"outputs": [
"dist/**", // Only dist files
"*.egg-info/**" // And egg-info
]
// Don't include: logs, temp files, etc.
}
}# Add this to your justfile
cache-clear:
@echo "π§Ή Clearing Turborepo cache..."
rm -rf .turbo
@echo "β
Cache cleared!"# Clear cache
just cache-clear
# Clear and rebuild
just cache-clear && just build- β After Turborepo version upgrade
- β When debugging cache issues
- β
After changing
turbo.jsonconfiguration - β When cache behavior seems incorrect
- β Not needed for normal development
# List cached tasks
ls -la .turbo/cache/
# View cache metadata
cat .turbo/cache/<hash>.json | jq .# Run task and note cache key
pnpm build --verbosity=2
# Make a change
echo "# comment" >> src/file.py
# Run again and compare keys
pnpm build --verbosity=2# Clear cache
rm -rf .turbo
# Run task
pnpm build
# Modify unrelated file
echo "# comment" >> README.md
# Should still cache hit
pnpm build| Scenario | Time | Cache Status |
|---|---|---|
| First build | 2-5s | Cache miss |
| No changes | 50-100ms | Cache hit (FULL TURBO) |
| One file changed | 500ms-1s | Partial cache hit |
| Config changed | 2-5s | Cache miss (all tasks) |
# Before optimization
time pnpm build
# After optimization
time pnpm build
# Calculate improvement
# (before - after) / before * 100 = % improvement- β
Include all relevant files in
inputs - β
Exclude generated files from
inputs - β Use specific glob patterns
- β Clear cache when debugging
- β Test cache behavior after config changes
- β Manually modify
.turbo/directory - β Include too many files in
inputs - β Add unnecessary task dependencies
- β Ignore cache misses
- β Commit
.turbo/to git (already in .gitignore)
When Turborepo isn't working as expected:
-
Check configuration
cat turbo.json
-
Verify clean working directory
git status
-
Clear cache and test
rm -rf .turbo pnpm build --force
-
Check for generated files
find . -name "*.pyc" -o -name "__pycache__"
-
Enable verbose logging
pnpm build --verbosity=2
-
Verify inputs/outputs
- Are all relevant files in
inputs? - Are
outputscorrectly specified? - Are there unnecessary dependencies?
- Are all relevant files in