{"record":{"id":"2d84d7e5d258ce83","repo":"withastro/astro","slug":"getstaticpathsrequired","errorCode":"GetStaticPathsRequired","errorMessage":"`getStaticPaths()` function is required for dynamic routes. Make sure that you `export` a `getStaticPaths()` function from your dynamic route.","messagePattern":"`getStaticPaths\\(\\)` function is required for dynamic routes\\. Make sure that you `export` a `getStaticPaths\\(\\)` function from your dynamic route\\.","errorType":"exception","errorClass":"AstroError","httpStatus":null,"severity":"error","filePath":"packages/astro/src/core/routing/validation.ts","lineNumber":18,"sourceCode":"import type { ComponentInstance } from '../../types/astro.js';\nimport type { GetStaticPathsResult } from '../../types/public/common.js';\nimport type { RouteData } from '../../types/public/internal.js';\nimport { AstroError, AstroErrorData } from '../errors/index.js';\n\n/** Error for deprecated or malformed route components */\nexport function validateDynamicRouteModule(\n\tmod: ComponentInstance,\n\t{\n\t\tssr,\n\t\troute,\n\t}: {\n\t\tssr: boolean;\n\t\troute: RouteData;\n\t},\n) {\n\tif ((!ssr || route.prerender) && route.origin !== 'internal' && !mod.getStaticPaths) {\n\t\tthrow new AstroError({\n\t\t\t...AstroErrorData.GetStaticPathsRequired,\n\t\t\tlocation: { file: route.component },\n\t\t});\n\t}\n}\n\n/** Throw error and log warnings for malformed getStaticPaths() response */\nexport function validateGetStaticPathsResult(result: GetStaticPathsResult, route: RouteData) {\n\tif (!Array.isArray(result)) {\n\t\tthrow new AstroError({\n\t\t\t...AstroErrorData.InvalidGetStaticPathsReturn,\n\t\t\tmessage: AstroErrorData.InvalidGetStaticPathsReturn.message(typeof result),\n\t\t\tlocation: {\n\t\t\t\tfile: route.component,\n\t\t\t},\n\t\t});\n\t}\n","sourceCodeStart":1,"sourceCodeEnd":36,"githubUrl":"https://github.com/withastro/astro/blob/52e6c34790cc8ac4e69e6135ace06049867e5c4a/packages/astro/src/core/routing/validation.ts#L1-L36","documentation":"In Astro, a dynamic route (one with [param] segments) that is prerendered must declare which paths exist at build time via an exported getStaticPaths(). validateDynamicRouteModule throws GetStaticPathsRequired when the route will be prerendered (static output, or an SSR build where the route has prerender = true), it is not an internal route, and the module exports no getStaticPaths. Without it the build would not know which pages to emit.","triggerScenarios":"Creating src/pages/[slug].astro with no export function getStaticPaths() while output is 'static' (the default); setting export const prerender = true on a dynamic route in an output:'server' project; forgetting the export keyword (function getStaticPaths(){} stays module-local); renaming the export (getStaticpath, getStaticPathsS).","commonSituations":"New projects adding a blog [slug] page from a tutorial but skipping getStaticPaths; switching output from 'server' to 'static' where dynamic routes relied on the server; flipping a route to prerender = true without porting its data loading; upgrading Astro 4 -> 5 and hitting stricter checks.","solutions":["Export getStaticPaths from the route: export async function getStaticPaths() { return (await getCollection('posts')).map(p => ({ params: { slug: p.slug } })); }","If the route must render on demand, keep the project SSR and set export const prerender = false in that route (requires an adapter).","If the route does not need to be dynamic, replace the [param] segment with a static filename."],"exampleFix":"// before\n// src/pages/blog/[slug].astro\n---\nconst { slug } = Astro.params;\n---\n\n// after\n// src/pages/blog/[slug].astro\n---\nexport async function getStaticPaths() {\n  const posts = await getCollection('blog');\n  return posts.map((post) => ({ params: { slug: post.slug }, props: { post } }));\n}\nconst { post } = Astro.props;\n---","handlingStrategy":"validation","validationCode":"// fails fast at module load with your own message, instead of during build\nimport type { GetStaticPaths } from 'astro';\n\nexport const getStaticPaths: GetStaticPaths = async () => {\n  /* ... */\n};","typeGuard":"import type { RouteParams } from 'astro';\n\nexport function hasGetStaticPaths(mod: Record<string, unknown>): mod is { getStaticPaths: () => unknown } {\n  return typeof mod.getStaticPaths === 'function';\n}","tryCatchPattern":null,"preventionTips":["Every dynamic [param] route in a static build must export getStaticPaths — treat the pair as one unit.","Type the export (GetStaticPaths) so forgetting it or misnaming it fails at typecheck.","When flipping prerender on a route, immediately port its data fetching into getStaticPaths()."],"tags":["astro","getstaticpaths","static-generation","prerendering","dynamic-routes"],"backgroundTag":"missing-getstaticpaths","analyzedSha":"52e6c34790cc8ac4e69e6135ace06049867e5c4a","analyzedAt":"2026-08-18T18:48:03.901Z","contentChangedAt":"2026-08-18T18:48:03.901Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}