Background
In packages/cli/src/commands/prerenderHandler.ts at line 206:
// TODO: This should come before we even bother detecting routes to prerender
const indexHtmlPath = path.join(getPaths().web.dist, 'index.html')
if (!fs.existsSync(indexHtmlPath)) {
console.error(
`You must run \`${formatCedarCommand(['build', 'web'])}\` before trying to prerender.`,
)
process.exit(1)
}
The prerender command currently:
- Runs
detectPrerenderRoutes() to find all routes marked for prerendering (~line 188)
- Filters to routes with paths
- Bails out if no prerender routes found
- Then checks if
web/dist/index.html exists — only now will it tell the user they forgot to build first
What needs to be done
Move the index.html existence check to the top of the handler, before route detection begins.
Why: Route detection may involve importing project code (Babel transforms, module loading). If web/dist doesn't exist, this is always going to fail — it's wasteful to do the detection work first. More importantly, the user gets a clearer, faster error message: "you need to build first" rather than potentially seeing a confusing detection error.
Change
In packages/cli/src/commands/prerenderHandler.ts, move the indexHtmlPath block (lines 206–214) to just after the getPaths() / import setup, before the detectPrerenderRoutes() call at line 188.
Before:
detectPrerenderRoutes() → filter routes → check no routes → check index.html → prerender
After:
check index.html → detectPrerenderRoutes() → filter routes → check no routes → prerender
This is a pure reorder with no logic changes — the behavior in the happy path is identical.
File
packages/cli/src/commands/prerenderHandler.ts, line 206
Background
In
packages/cli/src/commands/prerenderHandler.tsat line 206:The
prerendercommand currently:detectPrerenderRoutes()to find all routes marked for prerendering (~line 188)web/dist/index.htmlexists — only now will it tell the user they forgot to build firstWhat needs to be done
Move the
index.htmlexistence check to the top of the handler, before route detection begins.Why: Route detection may involve importing project code (Babel transforms, module loading). If
web/distdoesn't exist, this is always going to fail — it's wasteful to do the detection work first. More importantly, the user gets a clearer, faster error message: "you need to build first" rather than potentially seeing a confusing detection error.Change
In
packages/cli/src/commands/prerenderHandler.ts, move theindexHtmlPathblock (lines 206–214) to just after thegetPaths()/ import setup, before thedetectPrerenderRoutes()call at line 188.Before:
After:
This is a pure reorder with no logic changes — the behavior in the happy path is identical.
File
packages/cli/src/commands/prerenderHandler.ts, line 206