Repository navigation
Turborepo cache miss on consecutive builds when .next folder exists, even with identical hash
#11212
Replies: 2 comments
|
This is a known issue with Next.js standalone output and Turborepo. The problem is that Next.js modifies files during the build process, and these modifications cause Turborepo to detect changes in the outputs. Root cause: Potential fixes: 1. Use // next.config.ts
const nextConfig = {
output: "standalone",
experimental: {
outputFileTracingExcludes: {
"*": ["./cache/**"],
},
},
};2. More aggressive output exclusions "outputs": [
".next/standalone/**",
".next/static/**",
"!.next/cache/**",
"!.next/trace",
"!.next/package.json",
"!.next/build-manifest.json"
]3. Consider using 4. Check for timestamps in outputs # After build, check what files changed
find apps/web/.next -mmin -1 -type fThe files that show up after a build are likely what's invalidating your cache. 5. Alternative: Don't cache standalone output |
Uh oh!
There was an error while loading. Please reload this page.
Summary
The Strange Part
Same hash, different results:
After deleting
.next:Immediate next build:
Hash
1a6444a677c8bb2cis identical both times! π€My Configuration
turbo.json
{ "$schema": "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)
Project Structure
What Iβve Tried
!.next/**to inputs.next/cache/**from outputs.nextsubfolders.nextbefore buildCurrent Workaround
{ "scripts": { "build": "rimraf apps/*/.next && turbo run build" } }This works but defeats the purpose of caching.
Questions
output: 'standalone'config affecting cache behavior?outputFileTracingRootinterfering with Turborepo caching?.nextevery time?Impact
Thanks for any help! π
turborepo-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
turbo.json build task:
{ "build": { "dependsOn": ["^build"], "inputs": ["$TURBO_DEFAULT$", "!.next/**"], "outputs": [".next/**", "!.next/cache/**"] } }Remote Cache Settings
npx turbo loginnpx turbo linkAdditional information
No response
Example
https://github.com/PSriVignesH/turborepo-remote-cache
All reactions