{"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/d081033d5fe8e8a68c4bbbad4af9d2deb9c74bca/packages/astro/src/core/routing/validation.ts#L1-L36","documentation":"In static (SSG) output, or for any route marked prerender = true under SSR, every dynamic route must export a getStaticPaths() function. validateDynamicRouteModule throws AstroError code GetStaticPathsRequired when the module has no getStaticPaths export, the route is dynamic, and it is not an internal route.","triggerScenarios":"A dynamic route file such as src/pages/blog/[id].astro with no `export async function getStaticPaths()`, while output is 'static' (the default) or while `export const prerender = true` is set.","commonSituations":"Adding a new dynamic page and forgetting the export; converting a static page to dynamic; intending on-demand rendering but not setting prerender = false or not installing an adapter.","solutions":["Add `export async function getStaticPaths() { return [{ params: { id: '1' } }]; }` to the page.","If the page should be server-rendered, set `export const prerender = false;` and ensure an adapter is configured.","Switch output to 'server' in astro.config and install an adapter for full SSR."],"exampleFix":"// before\n// src/pages/blog/[id].astro with frontmatter only reading Astro.params.id\n// after\n---\nexport async function getStaticPaths() {\n  return [{ params: { id: '1' } }, { params: { id: '2' } }];\n}\n---","handlingStrategy":"validation","validationCode":"import { readdirSync, readFileSync } from 'node:fs';\nfunction assertDynamicRoutesExportGSP(dir) {\n  for (const f of readdirSync(dir)) {\n    if (!/\\[[^\\]]+\\]/.test(f) || !f.endsWith('.astro')) continue;\n    const src = readFileSync(`${dir}/${f}`, 'utf8');\n    if (!/export\\s+(async\\s+)?function\\s+getStaticPaths/.test(src) && !/prerender\\s*=\\s*false/.test(src)) {\n      throw new Error(`${f} is dynamic but has no getStaticPaths and is not prerender=false`);\n    }\n  }\n}","typeGuard":"const isDynamicRoute = (file: string) => /\\[[^\\]]+\\]/.test(file);\nconst needsGetStaticPaths = (src: string, output: string) =>\n  output !== 'server' && isDynamicRoute(src) &&\n  !/export\\s+(async\\s+)?function\\s+getStaticPaths/.test(src) &&\n  !/prerender\\s*=\\s*false/.test(src);","tryCatchPattern":null,"preventionTips":["Decide per dynamic route whether it is SSG (getStaticPaths) or SSR (prerender = false).","Install an adapter before relying on on-demand rendering.","Run `astro check` after adding dynamic routes."],"tags":["routing","getstaticpaths","ssr","build"],"backgroundTag":null,"analyzedSha":"d081033d5fe8e8a68c4bbbad4af9d2deb9c74bca","analyzedAt":"2026-08-12T13:37:29.035Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}