How to Clean Next.js (.next/cache) & Turborepo
Next.js is the backbone of modern web engineering, but its compiler aggressively saves SWC transform outputs, optimized WebP images, and server component chunks in .next/cache. If you have 5 to 10 Next.js repos, you likely have 25–60 GB of stale build artifacts. Here is how to purge them without losing source code or environment variables.
Why .next/cache Balloons to 5–15 GB Per Project
When you run npm run build or develop locally with next dev, Next.js writes:
- SWC compiler caches: Hundreds of thousands of AST transformations in
.next/cache/swc. - Next.js image optimizer: Processed responsive images in
.next/cache/images. - Webpack pack & fetch cache: Pre-rendered route JSON and server actions.
# Check the size of .next in your current project: du -sh .next du -sh .next/cache 2>/dev/null1. Clearing .next Caches via Terminal
The entire .next directory is 100% ephemeral and reproducible. You can safely wipe it at any time:
# Delete .next directory in the current project: rm -rf .next # Or delete only the compiler cache: rm -rf .next/cacheImportant note: Never delete .env.local or files in public/. Only delete the .next build folder.
2. Pruning Turborepo Monorepo Artifacts
If you use Turborepo (turbo), local build artifacts are stored in node_modules/.cache/turbo across all packages in the monorepo:
# Delete Turborepo cache across all workspaces: find . -name ".turbo" -type d -prune -exec rm -rf + rm -rf node_modules/.cache/turbo3. Bulk Prune Dormant .next Repositories with SpaceWise
Developers usually don't know which of their 30 client repositories have huge .next folders hoarding SSD space.
SpaceWise automatically indexes your code drives in milliseconds. Its Dormant Project Pruner flags projects untouched for 30+ days and presents an interactive summary of all .next, dist, and node_modules folders ready for safe, 1-click recycling.
- ✓Zero code risk: Never touches source files, git commits, or uncommitted work.
- ✓Reversible: Moves folders to OS Trash rather than executing permanent
rm -rf.
Do all of this in SpaceWise — for free
SpaceWise scans and safely cleans everything covered in this guide with one click. No Terminal required.
Download for Mac Free