Skip to content
Latchkey

Astro "getStaticPaths() is required for dynamic routes" in CI

In static output, Astro must know every path a dynamic route generates. A [param] route without getStaticPaths() gives the build no list of pages to prerender, so it errors. Either add getStaticPaths, or switch that route to SSR.

What this error means

The build fails with "getStaticPaths() function is required for dynamic routes" on a file like src/pages/blog/[slug].astro.

astro
[GetStaticPathsRequired] `getStaticPaths()` function is required for
dynamic routes. Make sure that you `export` a `getStaticPaths` function
from your dynamic route.
  File: src/pages/blog/[slug].astro

Common causes

A static dynamic route with no path list

The route uses a [param] segment but does not export getStaticPaths, so the static build cannot enumerate pages.

SSR expected but output is static

You meant the route to render on demand, but output is static, which requires prebuilt paths.

How to fix it

Export getStaticPaths for static generation

  1. Add a getStaticPaths that returns one entry per page, each with the route params.
  2. Read the param via Astro.params in the page.
  3. Rebuild to confirm the pages generate.
src/pages/blog/[slug].astro
export async function getStaticPaths() {
  const posts = await getPosts();
  return posts.map((p) => ({ params: { slug: p.slug } }));
}

Switch the route to SSR instead

If the route should render on demand, use server/hybrid output with an adapter and mark it non-prerendered.

src/pages/blog/[slug].astro
export const prerender = false;

How to prevent it

  • Export getStaticPaths from every static dynamic route.
  • Use SSR (server/hybrid) for routes that cannot be enumerated at build.
  • Keep the output mode consistent with how each route renders.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →