Is it safe to delete a Next.js project’s .next folder?
- Yes, with the dev server stopped.
.nextis what Next.js generated from your code: build output, caches and optimized images. None of it is source. - What it costs you: the next
next devstarts cold,next buildruns without its cache, andnext starthas nothing to serve until you build again. - Does it come back? Yes, on the next
next devornext build. - SiftMac’s verdict: Rebuilds
1. What’s inside .next
.next is Next.js’s build directory, its distDir. The docs say Next.js takes ownership of that directory and will sometimes delete its contents itself. In current versions it holds:
- The production build from
next build, whichnext startserves. .next/dev: output ofnext dev. Since Next.js 16, development builds go here, sonext devandnext buildcan run at the same time..next/cache: data kept between builds to make them faster, including Turbopack’s file system cache for builds (cache/turbopack, on by default since 16.3) and optimized images (cache/images)..next/dev/cache/turbopack: Turbopack’s cache for the dev server, on by default since 16.1.
The image cache has a ceiling. Unless you set one, Next.js checks the free disk space once at startup and lets the cache use half of it, then deletes the least recently used images beyond that. images.maximumDiskCacheSize in your Next.js config sets a lower limit, and 0 turns the disk cache off.
2. Where it is
~/Projects/my-site/.next
At the project root, next to next.config.js and package.json, unless distDir names another folder. In a monorepo each Next.js app has its own. To find them with their sizes:
find ~/Projects -type d -name .next -prune -exec du -sh {} + 2>/dev/null | sort -h
3. How big it gets
du -sh .next .next/cache .next/dev 2>/dev/null
The caches are the parts that grow from one run to the next: Turbopack keeps work from earlier builds and dev sessions, and the image cache keeps optimized images up to its limit. The production build itself is replaced by each new build.
4. How to delete it
- Stop
next devandnext startfor that project. - Delete the folder by its full path.
rm -rf ~/Projects/my-site/.next
To keep the last production build and clear only the caches, empty .next/cache instead:
rm -rf ~/Projects/my-site/.next/cache/*
If optimized images are out of date, Next.js’s docs say there’s no way to invalidate that cache yet: change the image’s src, or delete <distDir>/cache/images.
5. What happens afterwards
next devcompiles routes again as you open them, so the first page loads are slow until its cache fills.next buildtakes longer without.next/cache, which is why CI setups keep that folder between builds.next startfails untilnext buildhas run, because it serves the build that lived in.next.- Images are optimized again the first time each is requested.
- Your source,
publicfolder,node_modulesand environment files aren’t touched.
6. When to keep it
Keep .next on a machine that serves the site with next start, until a new build replaces it. In projects you’ve finished with, clear [node_modules](/safe-to-delete/node-modules) as well; it comes back with an install.
Questions
Is it safe to delete .next while next dev is running?
Stop it first: the dev server writes to .next/dev as you work. Delete the folder, start next dev again, and it rebuilds what it needs.
Why is my .next folder so big?
Look in .next/cache and .next/dev/cache first. Turbopack’s file system caches live there, and so does the optimized image cache, which by default may use up to half the free space Next.js saw when it started. images.maximumDiskCacheSize caps it.
Is .next/cache safe to delete on its own?
Yes. It only speeds up builds and image serving; the next build or request recreates what it needs, and the production build next to it stays usable.
Should CI keep .next/cache between builds?
Next.js recommends it: persisting .next/cache is what makes repeat builds faster, and a CI that doesn’t keep it may show a No Cache Detected message.
How SiftMac handles it. Its Developer files category lists .next folders that sit next to a package.json, in projects whose own files haven’t changed for 1, 3 or 6 months, as a web build cache, along with .nuxt, .svelte-kit, .turbo, .parcel-cache and .angular folders. None is ticked until you tick it.
Download SiftMac · scanning is free, and so is your first 2 GB of cleaning · See how it works