@@ -81,7 +81,11 @@ export async function prerenderPages(
81
81
}
82
82
83
83
// 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 (
85
89
workspaceRoot ,
86
90
outputFilesForWorker ,
87
91
assetsReversed ,
@@ -92,11 +96,15 @@ export async function prerenderPages(
92
96
verbose ,
93
97
) ;
94
98
99
+ if ( routesErrors ?. length ) {
100
+ errors . push ( ...routesErrors ) ;
101
+ }
102
+
95
103
if ( routesWarnings ?. length ) {
96
104
warnings . push ( ...routesWarnings ) ;
97
105
}
98
106
99
- if ( allRoutes . size < 1 ) {
107
+ if ( allRoutes . size < 1 || errors . length > 0 ) {
100
108
return {
101
109
errors,
102
110
warnings,
@@ -190,22 +198,27 @@ async function renderPages(
190
198
const isAppShellRoute = appShellRoute === route ;
191
199
const serverContext : ServerContext = isAppShellRoute ? 'app-shell' : 'ssg' ;
192
200
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
+ } ) ;
209
222
210
223
renderingPromises . push ( renderResult ) ;
211
224
}
@@ -231,7 +244,7 @@ async function getAllRoutes(
231
244
prerenderOptions : PrerenderOptions ,
232
245
sourcemap : boolean ,
233
246
verbose : boolean ,
234
- ) : Promise < { routes : Set < string > ; warnings ?: string [ ] } > {
247
+ ) : Promise < { routes : Set < string > ; warnings ?: string [ ] ; errors ?: string [ ] } > {
235
248
const { routesFile, discoverRoutes } = prerenderOptions ;
236
249
const routes = new RoutesSet ( ) ;
237
250
const { route : appShellRoute } = appShellOptions ;
@@ -275,8 +288,12 @@ async function getAllRoutes(
275
288
recordTiming : false ,
276
289
} ) ;
277
290
291
+ const errors : string [ ] = [ ] ;
278
292
const { routes : extractedRoutes , warnings } : RoutersExtractorWorkerResult = await renderWorker
279
293
. run ( { } )
294
+ . catch ( ( err ) => {
295
+ errors . push ( `An error occurred while extracting routes.\n\n${ err . stack } ` ) ;
296
+ } )
280
297
. finally ( ( ) => {
281
298
void renderWorker . destroy ( ) ;
282
299
} ) ;
@@ -285,7 +302,7 @@ async function getAllRoutes(
285
302
routes . add ( route ) ;
286
303
}
287
304
288
- return { routes, warnings } ;
305
+ return { routes, warnings, errors } ;
289
306
}
290
307
291
308
function addLeadingSlash ( value : string ) : string {
0 commit comments