Free Astro tutorials for complete beginners.

Beginner's Guide to Astro

How to Fix the GetStaticPathsRequired Error in Astro

Astro says getStaticPaths() function is required for dynamic routes? Your [slug].astro page needs a list of pages to build. Here's the fix, tested on Astro 7.4.

Tested on Astro 7.4

Cover image for How to Fix the GetStaticPathsRequired Error in Astro
In this guide
  1. Why it happens
  2. How to fix it
  3. Still stuck?
  4. Where to go next
  5. Frequently asked questions

You get GetStaticPathsRequired when a page file has square brackets in its name, like [slug].astro, but no getStaticPaths() function. Astro needs that function to know which pages to make. Add it to the top of the file and export it. Then the error goes away.

Why it happens

A file like src/pages/blog/[slug].astro is a dynamic route. One file makes many pages, such as /blog/hello/ and /blog/my-second-post/.

Astro builds a static site ahead of time. So it must know every page before anyone visits. getStaticPaths() hands it that list. Without the list, Astro doesn’t know what to fill in for slug.

We made this page in a fresh Astro 7.4 project:

---
const { slug } = Astro.params;
---
<h1>Post: {slug}</h1>

Then we ran the build. Here is the error, with the long file paths cut out:

Terminal
$ npm run build
[GetStaticPathsRequired] `getStaticPaths()` function is required for dynamic routes. Make sure that you `export` a `getStaticPaths()` function from your dynamic route.
Hint:
  See https://docs.astro.build/en/guides/routing/#dynamic-routes for more information on dynamic routes.
  If you meant for this route to be server-rendered, set `export const prerender = false;` in the page.
Error reference:
  https://docs.astro.build/en/reference/errors/get-static-paths-required/
Location:
  src/pages/blog/[slug].astro:0:0

You get it in npm run dev too, as soon as you open the page. The browser shows an error page called GetStaticPathsRequired.

How to fix it

  1. Open the file the error names. In our case, src/pages/blog/[slug].astro.
  2. Add getStaticPaths() at the top, inside the --- lines. Put export in front of it. Return one item for each page you want:
---
export function getStaticPaths() {
  return [
    { params: { slug: 'hello' } },
    { params: { slug: 'my-second-post' } },
  ];
}

const { slug } = Astro.params;
---
<h1>Post: {slug}</h1>
  1. Check the name matches. The word in the brackets must match the word in params. A file called [slug].astro needs slug. A file called [id].astro needs id.
  2. Build again. Run npm run build.

We did this, and the build worked. Astro made one page for each item in the list:

Terminal
$ npm run build
generating static routes
├─ /blog/hello/index.html (+3ms)
├─ /blog/my-second-post/index.html (+1ms)
├─ /index.html (+1ms)
[build] 3 page(s) built in 113ms
[build] Complete!

Still stuck?

Where to go next

Frequently asked questions

What is a dynamic route?

A page file with square brackets in its name, like [slug].astro. One file makes many pages, such as one for each blog post.

Why does Astro need a list of pages?

A static site is built ahead of time. Astro has to know every page before anyone visits. getStaticPaths gives it that list.

Can I skip getStaticPaths?

Only if the page runs on a server for each visitor. That needs an adapter and the line export const prerender = false. Most beginners should add getStaticPaths instead.

Stuck on a step?

Check the common errors guide, look up a word in the glossary, or ask the friendly people in the official Astro and EmDash Discords. How to ask so people can help.

Keep reading

  1. How to Register a Domain Name and Connect It to Your Astro Site

    Buy a domain for about $11 a year, then point it at Cloudflare or Netlify. We did this for astronursery.com, and these are the exact steps.

    Tutorials, 8 minute read, November 8, 2026

  2. How to Add Google Analytics to an Astro Site (and a Simpler Option)

    Paste Google's tag into your Astro layout with one small change, is:inline, and it works on every page. Or use Cloudflare Web Analytics, which needs no cookie banner.

    Tutorials, 6 minute read, November 8, 2026

  3. How to Add a Contact Form to an Astro Site (No Server Needed)

    A static site can't receive form submissions on its own. A free form service can. Here's a working contact form in ten lines, with spam protection built in.

    Tutorials, 7 minute read, November 8, 2026

Try "blog", "deploy" or "EmDash".