brokeinprod
brokeinprod
Theme

Debugging

The Times rm -rf .next Fixed It, and the Times It Didn't

Next.js has several cache layers, and `rm -rf .next` clears one. How to tell which cache is stale: browser, .next, App Router, or service worker.

December 1, 2026

rm -rf .next had become my reflex for anything strange. Then I ran it five times in a row, and the change still would not show.

Start here: Before you rm -rf .next, figure out which cache is stale. That command clears one of them. Change not showing in dev? Usually the browser. Hard-refresh or open a private window first. Stale data or pages in production but fine in dev? That is the App Router's data and route cache. Use revalidatePath or revalidateTag, not a .next wipe. A structural change or a stuck Turbopack or Tailwind build error? That is when rm -rf .next && npm run dev is the right tool. And if you run a PWA, an old service worker can serve stale files that no cache-clear touches. Unregister it in DevTools.

The setup

Over this build, "my change isn't showing up" happened more than once: a swapped hero image that would not change, a component that did not reflect a structural edit, a styling change that did not appear. rm -rf .next became my reflex. Sometimes it worked at once. Sometimes it did nothing, and I spent twenty minutes wiping a cache that was never the problem.

The lesson: rm -rf .next is treated as a universal reset, but Next.js caches in several independent layers, and that command clears one of them. Knowing which layer is stale is the difference between a five-second fix and an afternoon.

The trap: .next is one cache, not the cache

.next is the build and compile cache. Deleting it forces a full rebuild, which is useful for some stale states and useless for others. Here are the layers that cause "it's not updating," and the symptom that points to each.

1. The browser cache, and this is the one that fools everyone

If a change shows up in a private window but not your normal one, it was never Next.js. Your browser is holding old files. This is the single most common false alarm. Hard-refresh (Cmd/Ctrl+Shift+R) or use a private window to confirm before touching anything else. This is the same trap behind a favicon that will not update; the favicon write-up covers the same cache with a different symptom.

2. The .next build cache, where rm -rf .next is the answer

When the compiled output itself goes stale, through a structural component change that will not reflect, Fast Refresh breaking, or a build error that persists after you have fixed it, that is the .next directory, and clearing it is correct:

 
 
# stop the dev server, then:
rm -rf .next && npm run dev

A concrete case on this stack: with Tailwind v4 and Turbopack, a CSS syntax error can get cached so that even after you fix the typo, the error overlay persists until you delete .next. That is a known cache-invalidation rough edge, not your mistake.

3. The App Router runtime caches, where rm -rf .next does nothing

If your data or rendered pages are stale, fine in dev and stale in production, that is the App Router's Router Cache, Full Route Cache, or Data Cache, not the build cache. Wiping .next will not help. You revalidate instead:

 
 
import { revalidatePath, revalidateTag } from "next/cache";
// after a mutation:
revalidatePath("/blog");
// or, for tagged fetches:
revalidateTag("posts");

On Next.js 16, the newer Cache Components and use cache model gives you more explicit control over these boundaries.

4. The service worker, the silent one on PWAs

If your app is a PWA with a service worker, it can serve old cached files no matter how many times you clear other caches. Open DevTools → Application → Service Workers and unregister it during development. Know this exists before it costs you an hour, especially on a site that ships an offline-capable service worker.

The browser cache and the service worker waste the most time of the four, because they look like build problems. The build is the thing you control, so it is the thing you suspect. Neither of those two layers is in your repo.

The decision tree

  • Shows in a private window, not in the normal browser → browser cache (or a service worker). Hard refresh, or unregister the worker.
  • Structural change or stuck build error in dev → rm -rf .next && npm run dev.
  • Stale data or pages, fine in dev → App Router cache; revalidatePath or revalidateTag.
  • Still broken after clearing .next → escalate: also clear node_modules/.cache and .turbo, then reinstall.

What I'd do differently

Spend ten seconds on triage before the wipe. Open a private window, which rules out the browser, and ask whether this is stale data or a stale build. Those two checks send you to the right fix at once and save you from reflexively deleting a cache that was never the problem.


rm -rf .next is a precise tool, not a reset button. Learn which cache you are fighting, and the command earns its reputation only in the one case where it applies.

FAQ

Does rm -rf .next delete my code? No. It removes only the build cache and compiled output; your source files are untouched. Next.js rebuilds it on the next start.

Why does my change show in a private window but not my normal browser? That is browser cache (or a registered service worker), not Next.js. Hard-refresh, or unregister the worker in DevTools → Application.

My production data is stale but dev is fine. Does clearing .next help? No. That is the App Router's data and route cache. Use revalidatePath or revalidateTag (or Next 16's use cache controls), not a .next wipe.

Further reading

Keep reading

Newsletter

New posts in your inbox. No spam — unsubscribe anytime.

Occasional emails when we publish something worth your time. Unsubscribe anytime.

More about what you'll get on the newsletter page.

THEME
↑↓ navigate↵ openesc close