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].astroCommon 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
- Add a
getStaticPathsthat returns one entry per page, each with the route params. - Read the param via
Astro.paramsin the page. - 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
getStaticPathsfrom 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
Astro adapter / output mode mismatch (static vs server vs hybrid) in CIFix Astro build errors from an output-mode and adapter mismatch in CI - static output with SSR features, or s…
Astro "Unable to render" (SSR adapter missing/mismatched) in CIFix Astro "Unable to render" / adapter errors in CI - SSR output needs the correct adapter (@astrojs/node, ve…
Astro content collection schema (zod) validation failed in CIFix Astro content collection schema errors in CI - frontmatter did not match the zod schema in the collection…