How to Fix: Turbopack crashing in dev server after prolonged usage
Turbopack dev server crashes after running for hours usually point to a long-lived state problem rather than a random one-off failure. In practice, this issue is commonly triggered by stale watcher state, incremental cache growth, hot reload graph invalidation bugs, or an unreleased resource inside the development server process. If you leave Next.js running for an entire day, those small inconsistencies can accumulate until Turbopack exits, hangs, or starts throwing internal errors.
Table of Contents
Understanding the Root Cause
This bug typically appears in long-running development sessions because Turbopack maintains in-memory state for module graphs, file watchers, invalidation metadata, and rebuild queues. Over prolonged usage, several failure modes can stack up:
- File watcher drift: if the underlying filesystem watcher misses events or receives duplicate change notifications, the dependency graph can become inconsistent.
- Cache pressure: dev-mode caches grow as routes, components, and assets are edited. In some versions, memory is not released aggressively enough during extended sessions.
- Hot reload instability: repeated Fast Refresh cycles can leave parts of the graph in a partially invalid state, especially in larger apps or monorepos.
- Platform-specific watcher limits: macOS, Linux, and WSL can each behave differently when many files are observed for a long period.
- Known Turbopack regressions: because Turbopack evolves quickly, certain Next.js canary and stable versions may contain bugs that only show up after many rebuilds.
In short, the dev server works initially, but a prolonged runtime increases the chance that a small internal inconsistency turns into a crash. That is why a clean restart often fixes the issue temporarily: it resets the watch graph, incremental compiler state, and in-memory caches.
Step-by-Step Solution
The most reliable fix is to combine version verification, cache cleanup, dependency updates, and runtime mitigation. Follow these steps in order.
1. Verify your Next.js and Node.js versions
First, confirm whether you are on a version with a known Turbopack issue. Check your installed versions:
node -v
npm ls next
npm ls react
npm ls react-dom
If possible, move to the latest stable or canary version of Next.js where Turbopack fixes may already be included:
npm install next@latest react@latest react-dom@latest
If you want to test the newest Turbopack fixes specifically:
npm install next@canary
2. Clear the build cache
A stale .next directory can preserve problematic dev artifacts. Remove it completely before restarting:
rm -rf .next
On Windows PowerShell:
Remove-Item -Recurse -Force .next
3. Start the dev server with Turbopack again
npm run dev -- --turbopack
If your project uses a package script, confirm it maps correctly to Next.js dev mode.
4. Monitor memory growth during long sessions
If the crash happens only after many hours, inspect whether memory usage steadily increases. You can start Node with diagnostic output:
NODE_OPTIONS="--trace-gc" npm run dev -- --turbopack
On Windows CMD:
set NODE_OPTIONS=--trace-gc && npm run dev -- --turbopack
If memory climbs continuously without stabilizing, the issue may be a memory leak or cache-retention bug in the dev toolchain.
5. Reduce watcher complexity temporarily
If you are in a monorepo or a project with generated files, large asset trees, or symlinked packages, reduce the number of watched files. Exclude generated output, logs, and temporary directories from your workflow where possible. Also make sure your editor is not repeatedly regenerating files inside the project root.
6. Test without Turbopack to confirm the scope
Run the normal webpack-based dev server for comparison:
npm run dev
If the crash disappears there, the problem is likely isolated to Turbopack dev server behavior rather than your application code.
7. Reinstall dependencies to eliminate environment corruption
rm -rf node_modules package-lock.json
npm install
Or with pnpm:
rm -rf node_modules pnpm-lock.yaml
pnpm install
8. Use a temporary process restart strategy for long-running sessions
Until the upstream bug is fixed, many teams use a practical mitigation: restart the dev server every few hours or after major branch switches. This is not the ideal final fix, but it prevents stale long-lived compiler state from accumulating.
9. If the issue persists, capture a minimal reproduction
Since the reported issue references the Next.js repository, the best escalation path is to reproduce the crash with as little app-specific code as possible. Include:
- Next.js version
- Node.js version
- Operating system
- Whether the app is a monorepo
- Whether symlinks or generated files are involved
- Approximate runtime before failure
- Crash logs or stack trace
That information helps isolate whether the problem is in watch mode, Fast Refresh, or incremental graph invalidation.
10. Recommended working baseline
If you need a stable local setup today, use this sequence:
rm -rf .next node_modules
npm install
npm install next@latest react@latest react-dom@latest
npm run dev -- --turbopack
If it still crashes after prolonged usage, switch back temporarily:
npm run dev
That keeps development moving while you track upstream fixes.
Common Edge Cases
- Monorepo workspaces: shared packages, symlinks, and linked dependencies can multiply watcher complexity and trigger invalidation bugs more often.
- Generated files inside the app tree: codegen outputs, CMS sync files, or export artifacts can create constant watch churn.
- WSL or network-mounted folders: filesystem event delivery can be less reliable in virtualized or mounted environments.
- Editor extensions: some tools repeatedly rewrite config or cache files, causing unnecessary rebuild loops.
- Large asset directories: image-heavy or content-heavy repos may stress file watching and cache management over time.
- Node version mismatches: unsupported or less-tested Node versions can surface runtime instability that looks like a Turbopack bug.
- Branch switching without cleanup: changing many files while the dev server stays alive can leave stale module graph state behind.
FAQ
1. Why does restarting the dev server fix the problem temporarily?
Because a restart clears in-memory compiler state, watch subscriptions, and incremental caches. If the crash is caused by accumulated stale state, restarting resets the environment.
2. Is this caused by my application code or by Turbopack itself?
It can be either, but if the issue appears only with –turbopack and not with the default dev server, that strongly suggests a Turbopack-specific problem or an edge case exposed by its watch and rebuild model.
3. What is the safest workaround while waiting for an upstream fix?
Use the standard Next.js dev server without Turbopack for mission-critical work, keep Next.js updated, remove the .next cache when switching branches, and periodically restart long-running dev sessions.
Bottom line: this prolonged-runtime Turbopack crash is usually the result of long-lived dev server state becoming inconsistent over time. The fastest path is to update Next.js, clear caches, validate Node compatibility, compare behavior with and without Turbopack, and use restarts or the default dev server as a temporary mitigation until the upstream fix lands.