next.js
52ea3cba - Fix stale dev types causing build failure after route deletion (#86489)

Commit
28 days ago
Fix stale dev types causing build failure after route deletion (#86489) When running `next dev`, then stopping it, deleting a route, and running `next build`, the build would fail with a type error like: ``` .next/dev/types/validator.ts:78:39 Type error: Cannot find module '../../../app/simple-test/page.js' ``` The root cause here is a fundamental tension: we have **one tsconfig.json** that needs to serve **two different modes**. When `isolatedDevBuild` is enabled (which is the default), Next.js outputs types to different directories: - Development: `.next/dev/types/` - Production: `.next/types/` To avoid tsconfig.json changing every time you switch between dev and build (which causes git noise and forces IDE reloads), we proactively include both paths: ```json { "include": [ ".next/types/**/*.ts", ".next/dev/types/**/*.ts" ] } ``` The problem is that TypeScript checks ALL files matching these patterns. If `.next/dev/types/validator.ts` exists from a previous dev session and contains imports to routes that have since been deleted, TypeScript fails during build because those imports point to non-existent files. You might ask: why not just completely separate them with two tsconfigs? The issue is that would require users to know which tsconfig to use for their IDE, and switching between configs manually defeats the purpose of a seamless dev/build experience. The single tsconfig approach is intentional. The fix filters out `.next/dev/types` files programmatically when running type check during build, without touching tsconfig.json: ```typescript let fileNames = effectiveConfiguration.fileNames if (excludeDevTypes) { const devTypesPattern = /[/\\]\.next[/\\]dev[/\\]types[/\\]/ fileNames = fileNames.filter((fileName) => !devTypesPattern.test(fileName)) } ``` This way the tsconfig stays unchanged (no git churn, IDE stays happy), dev types are preserved for concurrent dev sessions, and build only type-checks its own `.next/types` directory.
Author
Parents
Loading