withastro/astro · error · AstroError
GetStaticPathsRequired
GetStaticPathsRequired
Error message
`getStaticPaths()` function is required for dynamic routes. Make sure that you `export` a `getStaticPaths()` function from your dynamic route.
What it means
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.
Source
Thrown at packages/astro/src/core/routing/validation.ts:18
import type { ComponentInstance } from '../../types/astro.js';
import type { GetStaticPathsResult } from '../../types/public/common.js';
import type { RouteData } from '../../types/public/internal.js';
import { AstroError, AstroErrorData } from '../errors/index.js';
/** Error for deprecated or malformed route components */
export function validateDynamicRouteModule(
mod: ComponentInstance,
{
ssr,
route,
}: {
ssr: boolean;
route: RouteData;
},
) {
if ((!ssr || route.prerender) && route.origin !== 'internal' && !mod.getStaticPaths) {
throw new AstroError({
...AstroErrorData.GetStaticPathsRequired,
location: { file: route.component },
});
}
}
/** 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,
},
});
}
View on GitHub (pinned to d081033d5f)
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.
Example fix
// before
// src/pages/blog/[id].astro with frontmatter only reading Astro.params.id
// after
---
export async function getStaticPaths() {
return [{ params: { id: '1' } }, { params: { id: '2' } }];
}
--- Defensive patterns
Strategy: validation
Validate before calling
import { readdirSync, readFileSync } from 'node:fs';
function assertDynamicRoutesExportGSP(dir) {
for (const f of readdirSync(dir)) {
if (!/\[[^\]]+\]/.test(f) || !f.endsWith('.astro')) continue;
const src = readFileSync(`${dir}/${f}`, 'utf8');
if (!/export\s+(async\s+)?function\s+getStaticPaths/.test(src) && !/prerender\s*=\s*false/.test(src)) {
throw new Error(`${f} is dynamic but has no getStaticPaths and is not prerender=false`);
}
}
} Type guard
const isDynamicRoute = (file: string) => /\[[^\]]+\]/.test(file); const needsGetStaticPaths = (src: string, output: string) => output !== 'server' && isDynamicRoute(src) && !/export\s+(async\s+)?function\s+getStaticPaths/.test(src) && !/prerender\s*=\s*false/.test(src);
Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- InvalidGetStaticPathsReturn
- InvalidGetStaticPathsEntry
- GetStaticPathsExpectedParams
- [RSS] You can only glob entries within 'src/pages/' when pas
- PrerenderClientAddressNotAvailable
AI-assisted analysis of withastro/astro@d081033d5f (2026-08-12).
Data as JSON: /api/errors/2d84d7e5d258ce83.
Report an issue: GitHub.