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

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:
$ 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:0You 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
- Open the file the error names. In our case,
src/pages/blog/[slug].astro. - Add
getStaticPaths()at the top, inside the---lines. Putexportin 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>
- Check the name matches. The word in the brackets must match the word in
params. A file called[slug].astroneedsslug. A file called[id].astroneedsid. - Build again. Run
npm run build.
We did this, and the build worked. Astro made one page for each item in the list:
$ 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?
- Read the official GetStaticPathsRequired page in the Astro docs.
- Paste your page file and the error into an AI. Our guide on fixing Astro errors with AI shows what to say.
- Ask in our community.
Where to go next
- How to fix the most common Astro errors for other errors you might hit.
- How to add a blog to Astro to build real post pages from a list.
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.