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.
[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.
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.
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.