AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

Dev Server Reads Zero-Byte Emitted Manifests During Rebuild Causing 500 Errors

In Next.js dev server (webpack), in-flight requests can read bundler-emitted manifests while they are zero bytes, leading to 'Manifest file is empty' or JSON parse errors. Occurs when concurrent requests overlap a rebuild; verified on next@16.3.0/16.3.1/canary.

highConfidence 92%Next.jsAffected V16.3.0Affected V16.3.1Affected Vcanary

Origin Analysis

RouteModule loads manifests with shouldCache: !this.isDev, so every request re-reads manifest files from disk. The bundler rewrites these files on each rebuild. A request landing between file creation and content write reads a zero-length file. The file is not torn but remains empty for a sustained window, so short retries fail. handleMissing only covers absent files, not empty existing files.
1. Clone https://github.com/Faolain/nextjs-dev-manifest-empty-race 2. Run npm install 3. Run npm run repro (boots dev server, hammers 12 App Router routes for 90s) 4. Script prints REPRODUCED and exits 0 when error appears in dev.log (usually within 30s). 5. Observe error: 'Error: Manifest file is empty' or 'SyntaxError: Unexpected end of JSON input'.

Fixing Code Block

Edge Case Audit

The fallback cache may serve stale manifest content during the zero-byte window; this could temporarily expose outdated client references or font data. After the rebuild completes, the cache refreshes on the next successful read. Risk of infinite waiting is bounded by MAX_EMPTY_RETRIES. The sync sleep uses SharedArrayBuffer, which requires a compatible Node runtime (Node 10+ with flag, Node 20+ default). In multi-threaded or worker contexts, the module-level fallbackCache is shared but reads/writes are synchronous, so no race within a single process; in cluster mode each worker has its own cache, which is acceptable. If a manifest legitimately becomes empty (should not happen), the fallback masks the error. Rollback: revert to the original loader files and remove the fallback; no database or external state is modified.

Ecosystem Topology