withastro/astro · error · AstroError
InvalidGetStaticPathsEntry
InvalidGetStaticPathsEntry
Error message
Invalid entry returned by `getStaticPaths()`. Expected an object, got `${entryType}`. What it means
Every element of the array returned by getStaticPaths() must be an object of the shape { params, props }. validateGetStaticPathsResult iterates the result and throws InvalidGetStaticPathsEntry when an entry is itself an array or null (typeof interpolated into the message). Arrays and null pass an Array.isArray(result) check on the outer value but are not valid entries.
Solutions
- Flatten/normalize so each entry is one { params, props } object: use Object.values(posts).map(...) instead of Object.entries(posts).
- Turn conditional maps into filter().map() so invalid entries never enter the array: posts.filter(p => p.published).map(...).
- Use .flatMap() correctly so nested arrays collapse to entry objects.
Example fix
// before
export function getStaticPaths() {
return posts.map((p) => p.published && { params: { slug: p.slug } }); // false entries
}
// after
export function getStaticPaths() {
return posts.filter((p) => p.published).map((p) => ({ params: { slug: p.slug } }));
} Defensive patterns
Strategy: type-guard
Type guard
function isEntryObject(v: unknown): v is { params: unknown; props?: unknown } {
return typeof v === 'object' && v !== null && !Array.isArray(v);
}
// entries.every(isEntryObject) must hold before returning from getStaticPaths Prevention
- Prefer filter().map() over boolean-returning map() so no false/null entries appear.
- Object.entries() yields arrays — map to objects explicitly.
- Annotate getStaticPaths' return type so the compiler rejects entry arrays/nulls.
When it happens
Trigger: Returning an array of arrays (e.g. a .flatMap() that produced nested arrays); including null entries from a .map() with a conditional return; returning [ ...Object.entries(posts) ] which yields [key, value] pairs; a filter chain that left undefined/null slots.
Common situations: Using Object.entries() to convert a keyed map instead of Object.values(); conditional mapping like posts.map(p => p.published && { params: ... }) which yields false/null entries; refactor from a nested-loop structure that kept inner arrays.
Related errors
- GetStaticPathsExpectedParams
- InvalidGetStaticPathsReturn
- getStaticPaths() ignored in dynamic page
- GetStaticPathsRequired
- Astro.generator inside getStaticPaths is deprecated and…
AI-assisted analysis of withastro/astro@52e6c34790 (2026-08-18).
Data as JSON: /api/errors/f02440a212198076.
Report an issue: GitHub.
Appendix: source
Thrown at packages/astro/src/core/routing/validation.ts:39
});
}
}
/** Throw error and log warnings for malformed getStaticPaths() response */
export function validateGetStaticPathsResult(result: GetStaticPathsResult, route: RouteData) {
if (!Array.isArray(result)) {
throw new AstroError({
...AstroErrorData.InvalidGetStaticPathsReturn,
message: AstroErrorData.InvalidGetStaticPathsReturn.message(typeof result),
location: {
file: route.component,
},
});
}
result.forEach((pathObject) => {
if ((typeof pathObject === 'object' && Array.isArray(pathObject)) || pathObject === null) {
throw new AstroError({
...AstroErrorData.InvalidGetStaticPathsEntry,
message: AstroErrorData.InvalidGetStaticPathsEntry.message(
Array.isArray(pathObject) ? 'array' : typeof pathObject,
),
});
}
if (
pathObject.params === undefined ||
pathObject.params === null ||
(pathObject.params && Object.keys(pathObject.params).length === 0)
) {
throw new AstroError({
...AstroErrorData.GetStaticPathsExpectedParams,
location: {
file: route.component,
},
});View on GitHub (pinned to 52e6c34790)