AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

Next.Js 16.3.0 Build Fails With Stale Dev Types (TS2307) When IsolatedDevBuild Is Enabled

Running `next build` after switching branches with `isolatedDevBuild` enabled leaves stale type definitions in `.next/dev/types` that are automatically included in tsconfig, causing TypeScript error TS2307.

highConfidence 85%Next.jsAffected V16.3.0

Origin Analysis

The `isolatedDevBuild` experimental feature in Next.js 16.3.0 does not clean up the `.next/dev/types` directory between branch switches. During development, type validator files are generated referencing route modules. When the branch changes and routes are removed, the stale validator still references the missing module, and `next build` includes these files via the automatically added tsconfig include paths, resulting in TS2307.
1. Clone the reproduction repo. 2. Run `npm ci`. 3. Run `npm run dev` and open `/api/hello` to generate dev types. 4. Switch to the `issue` branch where the route is removed. 5. Run `npm run build`. 6. Observe the TypeScript error: `.next/dev/types/validator.ts(62,39): error TS2307: Cannot find module '../../../app/api/hello/route.js'`.

Fixing Code Block

Edge Case Audit

This is a workaround that only addresses the stale dev types symptom. It may not resolve other stale artifacts (e.g., `.next/types`) and could break if the `prebuild` script fails on systems without Node.js (unlikely). The underlying issue in Next.js should be fixed upstream; consider monitoring for a patch. For rollback, simply remove the `prebuild` script from `package.json`.

Ecosystem Topology