@@ -20,14 +20,25 @@ export async function runTypeCheck(
2020 distDir : string ,
2121 tsConfigPath : string ,
2222 cacheDir ?: string ,
23- isAppDirEnabled ?: boolean
23+ isAppDirEnabled ?: boolean ,
24+ isolatedDevBuild ?: boolean
2425) : Promise < TypeCheckResult > {
2526 const effectiveConfiguration = await getTypeScriptConfiguration (
2627 typescript ,
2728 tsConfigPath
2829 )
2930
30- if ( effectiveConfiguration . fileNames . length < 1 ) {
31+ // When isolatedDevBuild is enabled, tsconfig includes both .next/types and
32+ // .next/dev/types to avoid config churn between dev/build modes. During build,
33+ // we filter out .next/dev/types files to prevent stale dev types from causing
34+ // errors when routes have been deleted since the last dev session.
35+ let fileNames = effectiveConfiguration . fileNames
36+ if ( isolatedDevBuild !== false ) {
37+ const devTypesPattern = / [ / \\ ] \. n e x t [ / \\ ] d e v [ / \\ ] t y p e s [ / \\ ] /
38+ fileNames = fileNames . filter ( ( fileName ) => ! devTypesPattern . test ( fileName ) )
39+ }
40+
41+ if ( fileNames . length < 1 ) {
3142 return {
3243 hasWarnings : false ,
3344 inputFilesCount : 0 ,
@@ -57,7 +68,7 @@ export async function runTypeCheck(
5768 }
5869 incremental = true
5970 program = typescript . createIncrementalProgram ( {
60- rootNames : effectiveConfiguration . fileNames ,
71+ rootNames : fileNames ,
6172 options : {
6273 ...options ,
6374 composite : false ,
@@ -66,10 +77,7 @@ export async function runTypeCheck(
6677 } ,
6778 } )
6879 } else {
69- program = typescript . createProgram (
70- effectiveConfiguration . fileNames ,
71- options
72- )
80+ program = typescript . createProgram ( fileNames , options )
7381 }
7482
7583 const result = program . emit ( )
@@ -147,7 +155,7 @@ export async function runTypeCheck(
147155 return {
148156 hasWarnings : true ,
149157 warnings,
150- inputFilesCount : effectiveConfiguration . fileNames . length ,
158+ inputFilesCount : fileNames . length ,
151159 totalFilesCount : program . getSourceFiles ( ) . length ,
152160 incremental,
153161 }
0 commit comments