Hi everyone! πI'm experiencing a strange caching issue with Turborepo and need help understanding if this is expected behavior or a bug.## The ProblemCache miss on consecutive builds when `.next` folder exists. Cache only works after manually deleting `.next`, even though the hash is identical.## Environment- **turbo:** 2.6.3- **next:** 16.0.1- **pnpm:** 9.14.2- **Node:** 22.19.0- **OS:** Windows 11## How to Reproduce```bash# Step 1: Clean everythingrm -rf apps/*/.next apps/*/.turbo .turbo# Step 2: First buildpnpm build# Result: cache miss β
(expected)# Step 3: Build again immediately (no changes)pnpm build# Expected: cache hit# Actual: cache miss β# Step 4: Delete .next foldersrm -rf apps/*/.next# Step 5: Build againpnpm build# Result: cache hit β
(3.7s - FULL TURBO)# Step 6: Build again immediatelypnpm build# Expected: cache hit# Actual: cache miss β (38s)The Strange Part
Same hash, different results:
After deleting .next:
web#build > cache hit, replaying logs 1a6444a677c8bb2cTime: 3.714s >>> FULL TURBOImmediate next build:
web#build > cache miss, executing 1a6444a677c8bb2cTime: 38.036sHash 1a6444a677c8bb2c is identical both times! π€
My Configuration
turbo.json
{ "$schema": "[https://turbo.build/schema.json](https://turbo.build/schema.json)", "ui": "tui", "tasks": { "//#biome-lint": { "inputs": [ "apps/**/*.{ts,tsx,js,jsx}", "packages/**/*.{ts,tsx,js,jsx}", "biome.json", "packages/biome-config/biome.json" ], "outputs": [] }, "//#biome-format": { "cache": false, "outputs": [] }, "//#biome-check": { "cache": false, "outputs": [] }, "type-check": { "dependsOn": ["^type-check"], "inputs": ["**/*.ts", "**/*.tsx", "tsconfig.json", "tsconfig.*.json"], "outputs": [] }, "build": { "dependsOn": ["^build"], "inputs": [ "$TURBO_DEFAULT$", "!Dockerfile*", "!*.dockerfile", "!.dockerignore", "!.next/**" ], "outputs": [ ".next/**", "!.next/cache/**", "!.next/trace/**", "!.next/analyze/**", "!.next/*.log", "!.next/BUILD_ID", "!.next/standalone/**/.env*", "!.next/standalone/**/node_modules/.cache/**" ] }, "dev": { "cache": false, "persistent": true } }}next.config.ts (same for both apps)
import type { NextConfig } from 'next'import { dirname, join } from 'node:path'import { fileURLToPath } from 'node:url'const Filename = fileURLToPath(import.meta.url)const Dirname = dirname(Filename)const nextConfig: NextConfig = { output: 'standalone', outputFileTracingRoot: join(Dirname, '../../'), transpilePackages: ['@repo/ui'], reactStrictMode: true, compress: true,}export default nextConfigProject Structure
turborepo/βββ apps/β βββ web/β β βββ next.config.tsβ βββ docs/β βββ next.config.tsβββ packages/β βββ ui/βββ turbo.jsonβββ package.jsonWhat Iβve Tried
| Attempt | Result |
|---|---|
Added !.next/** to inputs | Still cache miss |
Excluded .next/cache/** from outputs | Still cache miss |
Excluded multiple .next subfolders | Still cache miss |
| Restarted turbo daemon | Still cache miss |
| Cleared all caches | Still cache miss |
Deleted .next before build | β Cache works! |
Current Workaround
{ "scripts": { "build": "rimraf apps/*/.next && turbo run build" }}This works but defeats the purpose of caching.
Questions
- Is this expected behavior when output folder already exists?
- Is the
output: 'standalone'config affecting cache behavior? - Are my output exclusions causing issues?
- Is
outputFileTracingRootinterfering with Turborepo caching? - Anyone else experiencing this on Windows?
- Any proper fix besides deleting
.nextevery time?
Impact
- Every build takes 38s instead of 3.7s (10x slower)
- Local development caching completely broken
- CI/Docker works fine (fresh environment each time) Thanks for any help! π
## Current vs Expected Behavior### Expected BehaviorWhen running `pnpm build` consecutively without any code changes:- First build: cache miss (expected - no cache exists)- Second build: **cache hit** (should restore from cache)- Third build: **cache hit** (should restore from cache)Build time with cache hit: ~3.7s (FULL TURBO)### Current BehaviorWhen running `pnpm build` consecutively without any code changes:- First build: cache miss β
- Second build: **cache miss** β (rebuilds everything)- Third build: **cache miss** β (rebuilds everything)Build time: ~38s every time### The Workaround That WorksIf I delete `.next` folder before building:- `rm -rf apps/*/.next`- `pnpm build` β **cache hit** β
(3.7s)But immediately running `pnpm build` again β **cache miss** β### Summary| Scenario | Expected | Actual ||----------|----------|--------|| `.next` doesn't exist | cache hit | β
cache hit || `.next` exists | cache hit | β cache miss |The cache only works when the output folder doesn't exist, even though the hash is identical.
## Steps to Reproduce**Repository:** https://github.com/PSriVignesH/turborepo-remote-cache```bash# 1. Clonegit clone https://github.com/PSriVignesH/turborepo-remote-cachecd turborepo-remote-cachepnpm install# 2. Login to Vercel Remote Cachenpx turbo login# 3. Link to Remote Cachenpx turbo link# 4. First buildpnpm build# Result: cache will be hitβ
# 5. Second build (no changes)pnpm build# Result: cache HIT for both β
# 7. Make a small change to apps/web/app/page.tsx (add a comment or space)# 8. Build againpnpm build# Expected: cache miss for web, cache HIT for docs# Actual: cache miss for web β
, cache miss for docs β (BUG!)# 9. Build again (no changes)pnpm build# Expected: cache hit for both# Actual: cache miss for both β (BUG!)# 10. Delete .next foldersrm -rf apps/*/.next# 11. Build againpnpm build# Result: cache HIT for both β
(works!)# 12. Build again (with .next existing)pnpm build# Expected: cache hit for both# Actual: cache miss for both β (BUG!)
# Complete Copy-Paste Ready```markdown## Project Information**Repository:** https://github.com/PSriVignesH/turborepo-remote-cache### Framework & Versions| Package | Version ||---------|---------|| turbo | 2.6.3 || next | 16.0.1 || pnpm | 9.x || node | 22.19.0 |### Environment| Setting | Value ||---------|-------|| OS | Windows 11 (Git Bash/MINGW64) || Remote Cache | Vercel (enabled via `turbo login` & `turbo link`) || Build Mode | Standalone (`output: 'standalone'`) |### Project Structureturborepo-remote-cache/ βββ apps/ β βββ web/ # Next.js 16.0.1 β β βββ next.config.ts β β βββ app/page.tsx β βββ docs/ # Next.js 16.0.1 β βββ next.config.ts β βββ app/page.tsx βββ packages/ β βββ ui/ # Shared components βββ turbo.json βββ package.json βββ pnpm-workspace.yaml
### Key Configuration**next.config.ts (both apps):**```typescriptconst nextConfig: NextConfig = { output: 'standalone', outputFileTracingRoot: join(Dirname, '../../'), transpilePackages: ['@repo/ui'],}turbo.json build task:
{ "build": { "dependsOn": ["^build"], "inputs": ["$TURBO_DEFAULT$", "!.next/**"], "outputs": [".next/**", "!.next/cache/**"] }}Remote Cache Settings
- Logged in via
npx turbo login - Linked via
npx turbo link - Using Vercel Remote Cache