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

  1. Return a string for every parameter in the route: `{ id: String(product.id) }` or fetch IDs as strings.
  2. Ensure the callback returns one object per parameter set, covering ALL parameters declared in the route path.
  3. Add runtime validation/filtering: drop records with missing values before returning them.
  4. 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

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


AI-assisted analysis of angular/angular-cli@bb72145f9a (2026-08-30). Data as JSON: /api/errors/3a17fefc580f909e. Report an issue: GitHub.