Where Does Next.js Put Build Output and Cache?
Next.js builds into a .next folder in the app dir, with standalone output and cache inside it. Remappable via distDir.
Last updated
Every next build writes into .next next to your source: compiled pages, the static export, the image cache, and file traces for deployment. Nothing in there is precious, and deleting it is the standard first fix.
Two settings change the picture. distDir renames the folder, and output: 'standalone' adds a minimal server plus node_modules subset for Docker deploys. Both live in next.config.js, which stays outside .next itself.
Where Next.js stores this, by platform
[AppDir]\.next
Build output, cache, traces and (with output standalone) the deployable server. Safe to delete; rebuild regenerates it. Rename via distDir in next.config.js.
[AppDir]/.next
Same layout. The standalone server runs with node .next/standalone/server.js; copy public and .next/static alongside it for self-hosting.
[AppDir]/.next
Same layout. In monorepos the tracing root is the app package dir, so files outside it never enter the traces regardless of distDir.
Frequently asked questions
My Next.js build acts haunted. How do I clean it?
Delete the .next folder and rebuild. It holds only generated output (cache, server bundles, traces), so a clean rebuild fixes most haunted build errors.
Can I build into a folder other than .next?
Set distDir in next.config.js (for example distDir: 'build'). Next.js refuses paths outside the app, and it owns the folder, so point it somewhere disposable.
Notice an outdated path? Let us know.