Astro "getStaticPaths() function required for dynamic routes" in CI
In Astro's static (SSG) output, a dynamic route file such as [slug].astro must export getStaticPaths() so the build knows which concrete paths to generate. Without it, Astro cannot enumerate the pages and fails the build.
What this error means
astro build fails with "getStaticPaths() function required for dynamic routes" naming a src/pages/[param].astro file. It builds only when output is SSR or the function is added.
[GetStaticPathsRequired] getStaticPaths() function required for dynamic routes.
Hint: See https://docs.astro.build/en/reference/routing-reference/#getstaticpaths
File: src/pages/blog/[slug].astroCommon causes
A dynamic route in a static build with no path list
The default static output cannot guess the parameter values; getStaticPaths() must return them at build time.
getStaticPaths returns an empty or wrong shape
A function that returns nothing, or objects missing params, gives the build no valid paths to render.
How to fix it
Export getStaticPaths returning the params
Return one object per page with a params map matching the route parameter.
export async function getStaticPaths() {
const posts = await getPosts();
return posts.map((p) => ({ params: { slug: p.slug } }));
}Switch the route to SSR if paths are dynamic
When pages are not known at build time, render on demand with an adapter so getStaticPaths is not required.
export const prerender = false;How to prevent it
- Add
getStaticPaths()to every dynamic page in a static build. - Return a non-empty array of
{ params }objects. - Use
prerender = falseplus an adapter for truly dynamic routes.