Skip to content
Latchkey

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.

astro
[GetStaticPathsRequired] getStaticPaths() function required for dynamic routes.
  Hint: See https://docs.astro.build/en/reference/routing-reference/#getstaticpaths
  File: src/pages/blog/[slug].astro

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

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 if paths are dynamic

When pages are not known at build time, render on demand with an adapter so getStaticPaths is not required.

src/pages/blog/[slug].astro
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 = false plus an adapter for truly dynamic routes.

Frequently asked questions

What causes ""getStaticPaths() function required""?
The default static output cannot guess the parameter values; getStaticPaths() must return them at build time.
How do I fix "getStaticPaths() function required"?
Return one object per page with a params map matching the route parameter.

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card