Skip to content

fix(prerender): check for web/dist/index.html before detecting routes #1594

@lisa-assistant

Description

@lisa-assistant

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:

  1. Runs detectPrerenderRoutes() to find all routes marked for prerendering (~line 188)
  2. Filters to routes with paths
  3. Bails out if no prerender routes found
  4. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions