facebook/docusaurus · error · Error

Some created redirects are invalid: - ${redirectValidationEr

Error message

Some created redirects are invalid:
- ${redirectValidationErrors.join('\n- ')}

What it means

Thrown by validateCollectedRedirects() in @docusaurus/plugin-client-redirects when at least one collected redirect fails validateRedirect() (e.g. malformed from/to). All collected redirects are validated and their error messages aggregated, so the thrown message lists every offending redirect at once.

Source

Thrown at packages/docusaurus-plugin-client-redirects/src/collectRedirects.ts:84

  return filterUnwantedRedirects(redirects, pluginContext);
}

function validateCollectedRedirects(
  redirects: RedirectItem[],
  pluginContext: PluginContext,
) {
  const redirectValidationErrors = redirects
    .map((redirect) => {
      try {
        validateRedirect(redirect);
        return undefined;
      } catch (err) {
        return (err as Error).message;
      }
    })
    .filter(Boolean);
  if (redirectValidationErrors.length > 0) {
    throw new Error(
      `Some created redirects are invalid:
- ${redirectValidationErrors.join('\n- ')}
`,
    );
  }

  const allowedToPaths = pluginContext.relativeRoutesPaths.map((p) =>
    decodeURI(p),
  );
  const toPaths = redirects
    .map((redirect) => redirect.to)
    // We now allow "to" to contain any string
    // We only do this "broken redirect" check from to that looks like pathnames
    // note: we allow querystring/anchors
    // See https://github.com/facebook/docusaurus/issues/6845
    .map((to) => {
      if (to.startsWith('/')) {
        const url = URL.parse(to, 'https://example.com');

View on GitHub (pinned to 3f483e80e3)

Solutions

  1. Read the bulleted list in the error: each line is one validateRedirect failure message naming the bad redirect.
  2. Fix each listed redirect's from/to to be valid absolute internal paths (leading slash).
  3. If using createRedirects, ensure it only returns strings starting with '/' (or [] / '' for none).
  4. Re-run the build to confirm no further validation errors.

Example fix

// before
createRedirects: (path) => 'old' + path,   // no leading slash
// after
createRedirects: (path) => '/old' + path,
Defensive patterns

Strategy: validation

Validate before calling

function isValidRedirectPath(p: string): boolean {
  return typeof p === 'string' && p.startsWith('/') && p.length > 1;
}
// validate createRedirects output before returning it:
const froms = (createRedirects?.(path) ?? []);
const arr = Array.isArray(froms) ? froms : [froms];
arr.forEach((f) => { if (!isValidRedirectPath(f)) throw new Error(`Bad redirect from: ${f}`); });

Type guard

const isRedirectItem = (r: unknown): r is {from: string; to: string} =>
  !!r && typeof (r as any).from === 'string' && typeof (r as any).to === 'string'
  && (r as any).from.startsWith('/') && (r as any).to.startsWith('/');

Prevention

When it happens

Trigger: Configuring fromExtensions/toExtensions/redirects/createRedirects in a way that produces a RedirectItem with a from or to that fails validateRedirect (e.g. relative path not starting with '/', empty string, external URL in a field that expects an internal path). Reached during build when collectRedirects runs.

Common situations: A createRedirects callback returning a path without a leading slash; an extensions config producing an empty from; a redirects option with from:'' or to:''; trailing-slash mismatches that produce an invalid combination.

Related errors


AI-assisted analysis of facebook/docusaurus@3f483e80e3 (2026-08-12). Data as JSON: /api/errors/a4b996c5411a1526. Report an issue: GitHub.