angular/angular-cli · error · Error

Could not find any routes to prerender.

Error message

Could not find any routes to prerender.

What it means

getRoutes collects the routes to prerender from builder options (routes, guessFilename, and extracted routes from the build output). If, after merging all sources, the route set is empty, there is nothing to render and the builder throws this error instead of producing an empty prerender output.

Source

Thrown at packages/angular_devkit/build_angular/src/builders/prerender/index.ts:88

        indexFile,
        outputPath,
        serverBundlePath,
        zonePackage,
      } as RoutesExtractorWorkerData,
      recordTiming: false,
    });

    const extractedRoutes: string[] = await renderWorker
      .run({})
      .finally(() => void renderWorker.destroy());

    for (const route of extractedRoutes) {
      routes.add(route);
    }
  }

  if (routes.size === 0) {
    throw new Error('Could not find any routes to prerender.');
  }

  return [...routes];
}

/**
 * Schedules the server and browser builds and returns their results if both builds are successful.
 */
async function _scheduleBuilds(
  options: PrerenderBuilderOptions,
  context: BuilderContext,
): Promise<
  BuilderOutput & {
    serverResult?: ServerBuilderOutput;
    browserResult?: BrowserBuilderOutput;
  }
> {
  const browserTarget = targetFromTargetString(options.browserTarget);

View on GitHub (pinned to bb72145f9a)

Solutions

  1. Add routes to the prerender target options: `"routes": ["/", "/about"]`.
  2. Provide a routesFile (one route per line) and verify its path and contents.
  3. Check that route discovery/extraction in the app is enabled and emits routes in the build output.
  4. Verify your app's routing actually declares the routes you expect to be discovered.

Example fix

// before (angular.json)
"prerender": { "builder": "@angular-devkit/build-angular:prerender", "options": {} }
// after
"prerender": {
  "builder": "@angular-devkit/build-angular:prerender",
  "options": { "routes": ["/", "/products"] }
}
Defensive patterns

Strategy: validation

Validate before calling

const routes = options.routes?.length ? options.routes
  : options.routesFile ? fs.readFileSync(options.routesFile, 'utf-8').split('\n').filter(Boolean)
  : [];
if (routes.length === 0) {
  throw new Error('Configure prerender "routes" or a non-empty "routesFile".');
}

Try / catch

try {
  await ngRun('my-app:prerender');
} catch (e) {
  if (e.message.includes('Could not find any routes to prerender')) {
    console.error('Add "routes" or "routesFile" to prerender options.');
  } else throw e;
}

Prevention

When it happens

Trigger: Running the prerender builder with no `routes` specified, no `routesFile`, and the application build's extraction (AppShell/route discovery) produced no routes; an empty or misformatted routes file yielding zero parsed routes.

Common situations: Forgetting to configure `routes` in angular.json prerender options; a routes file with blank lines/comments only or wrong path; upgrading to application-builder versions where routes must be declared explicitly instead of inferred.

Related errors


AI-assisted analysis of angular/angular-cli@bb72145f9a (2026-08-30). Data as JSON: /api/errors/f8c01f9c412f134e. Report an issue: GitHub.