@@ -579,7 +579,23 @@ export function generateValidatorFile(
579
579
}
580
580
581
581
// Build import statement based on what's actually needed
582
- const routeImports = [ 'AppRoutes' , 'LayoutRoutes' , 'ParamMap' ]
582
+ const routeImports = [ ]
583
+
584
+ // Only import AppRoutes if there are app pages
585
+ if ( appPageValidations ) {
586
+ routeImports . push ( 'AppRoutes' )
587
+ }
588
+
589
+ // Only import LayoutRoutes if there are layouts
590
+ if ( layoutValidations ) {
591
+ routeImports . push ( 'LayoutRoutes' )
592
+ }
593
+
594
+ // Only import ParamMap if there are routes that use it
595
+ if ( appPageValidations || layoutValidations || appRouteHandlerValidations ) {
596
+ routeImports . push ( 'ParamMap' )
597
+ }
598
+
583
599
if ( hasAppRouteHandlers ) {
584
600
routeImports . push ( 'AppRouteHandlerRoutes' )
585
601
}
@@ -593,13 +609,18 @@ export function generateValidatorFile(
593
609
? "import type { NextRequest } from 'next/server.js'\n"
594
610
: ''
595
611
612
+ // Only import metadata types if there are App Router pages or layouts that might use them
613
+ const metadataImport =
614
+ appPageValidations || layoutValidations
615
+ ? 'import type { ResolvingMetadata, ResolvingViewport } from "next/dist/lib/metadata/types/metadata-interface.js"\n'
616
+ : ''
617
+
596
618
return `// This file is generated automatically by Next.js
597
619
// Do not edit this file manually
598
620
// This file validates that all pages and layouts export the correct types
599
621
600
622
${ routeImportStatement }
601
- import type { ResolvingMetadata, ResolvingViewport } from "next/dist/lib/metadata/types/metadata-interface.js"
602
- ${ nextRequestImport }
623
+ ${ metadataImport } ${ nextRequestImport }
603
624
${ typeDefinitions }
604
625
${ appPageValidations }
605
626
0 commit comments