@@ -81,7 +81,11 @@ export async function prerenderPages(
8181 }
8282
8383 // Get routes to prerender
84- const { routes : allRoutes , warnings : routesWarnings } = await getAllRoutes (
84+ const {
85+ routes : allRoutes ,
86+ warnings : routesWarnings ,
87+ errors : routesErrors ,
88+ } = await getAllRoutes (
8589 workspaceRoot ,
8690 outputFilesForWorker ,
8791 assetsReversed ,
@@ -92,11 +96,15 @@ export async function prerenderPages(
9296 verbose ,
9397 ) ;
9498
99+ if ( routesErrors ?. length ) {
100+ errors . push ( ...routesErrors ) ;
101+ }
102+
95103 if ( routesWarnings ?. length ) {
96104 warnings . push ( ...routesWarnings ) ;
97105 }
98106
99- if ( allRoutes . size < 1 ) {
107+ if ( allRoutes . size < 1 || errors . length > 0 ) {
100108 return {
101109 errors,
102110 warnings,
@@ -190,22 +198,27 @@ async function renderPages(
190198 const isAppShellRoute = appShellRoute === route ;
191199 const serverContext : ServerContext = isAppShellRoute ? 'app-shell' : 'ssg' ;
192200 const render : Promise < RenderResult > = renderWorker . run ( { route, serverContext } ) ;
193- const renderResult : Promise < void > = render . then ( ( { content, warnings, errors } ) => {
194- if ( content !== undefined ) {
195- const outPath = isAppShellRoute
196- ? 'index.html'
197- : posix . join ( removeLeadingSlash ( route ) , 'index.html' ) ;
198- output [ outPath ] = content ;
199- }
200-
201- if ( warnings ) {
202- warnings . push ( ...warnings ) ;
203- }
204-
205- if ( errors ) {
206- errors . push ( ...errors ) ;
207- }
208- } ) ;
201+ const renderResult : Promise < void > = render
202+ . then ( ( { content, warnings, errors } ) => {
203+ if ( content !== undefined ) {
204+ const outPath = isAppShellRoute
205+ ? 'index.html'
206+ : posix . join ( removeLeadingSlash ( route ) , 'index.html' ) ;
207+ output [ outPath ] = content ;
208+ }
209+
210+ if ( warnings ) {
211+ warnings . push ( ...warnings ) ;
212+ }
213+
214+ if ( errors ) {
215+ errors . push ( ...errors ) ;
216+ }
217+ } )
218+ . catch ( ( err ) => {
219+ errors . push ( `An error occurred while prerendering route '${ route } '.\n\n${ err . stack } ` ) ;
220+ void renderWorker . destroy ( ) ;
221+ } ) ;
209222
210223 renderingPromises . push ( renderResult ) ;
211224 }
@@ -231,7 +244,7 @@ async function getAllRoutes(
231244 prerenderOptions : PrerenderOptions ,
232245 sourcemap : boolean ,
233246 verbose : boolean ,
234- ) : Promise < { routes : Set < string > ; warnings ?: string [ ] } > {
247+ ) : Promise < { routes : Set < string > ; warnings ?: string [ ] ; errors ?: string [ ] } > {
235248 const { routesFile, discoverRoutes } = prerenderOptions ;
236249 const routes = new RoutesSet ( ) ;
237250 const { route : appShellRoute } = appShellOptions ;
@@ -275,8 +288,12 @@ async function getAllRoutes(
275288 recordTiming : false ,
276289 } ) ;
277290
291+ const errors : string [ ] = [ ] ;
278292 const { routes : extractedRoutes , warnings } : RoutersExtractorWorkerResult = await renderWorker
279293 . run ( { } )
294+ . catch ( ( err ) => {
295+ errors . push ( `An error occurred while extracting routes.\n\n${ err . stack } ` ) ;
296+ } )
280297 . finally ( ( ) => {
281298 void renderWorker . destroy ( ) ;
282299 } ) ;
@@ -285,7 +302,7 @@ async function getAllRoutes(
285302 routes . add ( route ) ;
286303 }
287304
288- return { routes, warnings } ;
305+ return { routes, warnings, errors } ;
289306}
290307
291308function addLeadingSlash ( value : string ) : string {
0 commit comments