{"record":{"id":"c8986241aeddde7d","repo":"withastro/astro","slug":"invalidgetstaticpathsreturn","errorCode":"InvalidGetStaticPathsReturn","errorMessage":"Invalid type returned by `getStaticPaths()`. Expected an `array`, got `${returnType}`.","messagePattern":"Invalid type returned by `getStaticPaths\\(\\)`\\. Expected an `array`, got `(.+?)`\\.","errorType":"exception","errorClass":"AstroError","httpStatus":null,"severity":"error","filePath":"packages/astro/src/core/routing/validation.ts","lineNumber":28,"sourceCode":"\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\n\tresult.forEach((pathObject) => {\n\t\tif ((typeof pathObject === 'object' && Array.isArray(pathObject)) || pathObject === null) {\n\t\t\tthrow new AstroError({\n\t\t\t\t...AstroErrorData.InvalidGetStaticPathsEntry,\n\t\t\t\tmessage: AstroErrorData.InvalidGetStaticPathsEntry.message(\n\t\t\t\t\tArray.isArray(pathObject) ? 'array' : typeof pathObject,\n\t\t\t\t),\n\t\t\t});\n\t\t}\n","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/withastro/astro/blob/52e6c34790cc8ac4e69e6135ace06049867e5c4a/packages/astro/src/core/routing/validation.ts#L10-L46","documentation":"getStaticPaths() must return a plain array of { params, props } entry objects. validateGetStaticPathsResult checks Array.isArray on the returned value and throws InvalidGetStaticPathsReturn (with typeof interpolated into the message) when it is anything else — an object map, a string, undefined, a Promise-like that was not awaited, etc. The route params cannot be derived from a non-array shape.","triggerScenarios":"Returning an object keyed by slug (return { 'a': {...}, 'b': {...} }); returning a single entry instead of a list (return { params: { slug: 'a' } }); forgetting await on an async fetch inside getStaticPaths so a Promise leaks; returning undefined because of a missing return in an if-branch; returning a Map or generator.","commonSituations":"Porting data from a CMS keyed as an object; early-return code paths that forget to return; getStaticPaths declared async but the final .map() chain dropped; returning getCollection(...) directly thinking it is an array.","solutions":["Make the function return an array: wrap object values with Object.values(map).map(...) or ensure every code path returns the array.","If getStaticPaths is async, await all async calls before returning (return (await getPosts()).map(...)).","Return [] (empty array) explicitly when the collection is empty, instead of undefined."],"exampleFix":"// before\nexport async function getStaticPaths() {\n  const res = fetch('https://api.example.com/posts'); // missing await\n  return res.json().map((p) => ({ params: { slug: p.slug } }));\n}\n\n// after\nexport async function getStaticPaths() {\n  const res = await fetch('https://api.example.com/posts');\n  const posts = await res.json();\n  return posts.map((p) => ({ params: { slug: p.slug } }));\n}","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"type StaticPath = { params: Record<string, string | undefined>; props?: Record<string, unknown> };\n\nfunction isStaticPathArray(v: unknown): v is StaticPath[] {\n  return (\n    Array.isArray(v) &&\n    v.every((e) => typeof e === 'object' && e !== null && !Array.isArray(e) && 'params' in e)\n  );\n}\n\n// const paths = await getStaticPaths();\n// if (!isStaticPathArray(paths)) throw new TypeError('getStaticPaths must return { params }[]');","tryCatchPattern":null,"preventionTips":["Always return an array; convert keyed maps with Object.values(...).map(...).","Ensure every branch of getStaticPaths returns (no bare early exits).","Await async data before returning so a Promise never leaks out."],"tags":["astro","getstaticpaths","static-generation","validation"],"backgroundTag":"getstaticpaths-validation-failed","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"}