angular/angular-cli · error · Error
The 'getPrerenderParams' function defined for the '${stripLe
Error message
The 'getPrerenderParams' function defined for the '${stripLeadingSlash(currentRoutePath)}' route returned a non-string value for parameter '${parameterName}'. Please make sure the 'getPrerenderParams' function returns values for all parameters specified in this route. What it means
When prerendering a parameterized route, the `getPrerenderParams` callback returns values that are substituted into the route path. This error fires when the returned value for a parameter is not a `string` (undefined, number, object, etc.), so the path template cannot be safely expanded. It guarantees the generated route tree contains valid string-only parameter values.
Source
Thrown at packages/angular/ssr/src/routes/ng-routes.ts:520
}
/**
* Creates a replacer function used for substituting parameter placeholders in a route path
* with their corresponding values provided in the `params` object.
*
* @param params - An object mapping parameter names to their string values.
* @param currentRoutePath - The current route path, used for constructing error messages.
* @returns A function that replaces a matched parameter placeholder (e.g., ':id') with its corresponding value.
*/
function handlePrerenderParamsReplacement(
params: Record<string, string>,
currentRoutePath: string,
): (substring: string, ...args: unknown[]) => string {
return (match) => {
const parameterName = match.slice(1);
const value = params[parameterName];
if (typeof value !== 'string') {
throw new Error(
`The 'getPrerenderParams' function defined for the '${stripLeadingSlash(currentRoutePath)}' route ` +
`returned a non-string value for parameter '${parameterName}'. ` +
`Please make sure the 'getPrerenderParams' function returns values for all parameters ` +
'specified in this route.',
);
}
return parameterName === '**' ? `/${value}` : value;
};
}
/**
* Resolves the `redirectTo` property for a given route.
*
* This function processes the `redirectTo` property to ensure that it correctly
* resolves relative to the current route path. If `redirectTo` is an absolute path,
* it is returned as is. If it is a relative path, it is resolved based on the current route path.
*View on GitHub (pinned to bb72145f9a)
Solutions
- Return a string for every parameter in the route: `{ id: String(product.id) }` or fetch IDs as strings.
- Ensure the callback returns one object per parameter set, covering ALL parameters declared in the route path.
- Add runtime validation/filtering: drop records with missing values before returning them.
- Run `ng build` with a `console.log` inside `getPrerenderParams` to see the exact offending parameter and value.
Example fix
// before
getPrerenderParams: async () => {
const products = await getProducts();
return products.map(p => ({ id: p.id })); // p.id is a number
}
// after
getPrerenderParams: async () => {
const products = await getProducts();
return products.filter(p => p.id != null).map(p => ({ id: String(p.id) }));
} Defensive patterns
Strategy: validation
Validate before calling
// validate before returning from getPrerenderParams
const raw = await fetchIds();
const params = raw.map(p => ({ id: String(p.id) }));
for (const p of params) {
if (typeof p.id !== 'string') throw new Error('id must be a string');
}
return params; Type guard
function hasStringParams(route: string, obj: Record<string, unknown>): obj is Record<string, string> {
const names = [...route.matchAll(/:(\w+)/g)].map(m => m[1]);
return names.every(n => typeof obj[n] === 'string');
} Try / catch
try {
await prerenderRoutes(...);
} catch (e) {
const m = /non-string value for parameter '(\w+)'/.exec(e.message);
if (m) console.error(`Parameter '${m[1]}' must be a string in getPrerenderParams`);
else throw e;
} Prevention
- Coerce all IDs to strings (`String(id)`) before returning from `getPrerenderParams`.
- Return one object per generated page covering every `:param` in the route path.
- Filter out records with null/undefined values before mapping to params.
- Enable strict TypeScript so missing object keys are caught at compile time.
When it happens
Trigger: `getPrerenderParams: async () => [{ id: 123 }]` (number instead of string), a missing key for one of the route's `:param` segments, or returning `undefined` from an async lookup in `handlePrerenderParamsReplacement` during `prerenderRoutes`/build.
Common situations: Fetching IDs from a CMS/API where some records return numeric IDs or null; forgetting a parameter defined in the route (e.g. route has `:category/:slug` but callback only returns `slug`); TypeScript not strict so objects lack required keys.
Related errors
- 'handleSSGRoute' was called for a route which rendering mode
- Could not find any routes to prerender.
- The builder requires a target.
- Rendering failed with ${numErrors} worker errors.
- A module or bootstrap option must be provided.
AI-assisted analysis of angular/angular-cli@bb72145f9a (2026-08-30).
Data as JSON: /api/errors/3a17fefc580f909e.
Report an issue: GitHub.