{"record":{"id":"a4b996c5411a1526","repo":"facebook/docusaurus","slug":"some-created-redirects-are-invalid-redirectva","errorCode":null,"errorMessage":"Some created redirects are invalid:\n- ${redirectValidationErrors.join('\\n- ')}\n","messagePattern":"Some created redirects are invalid:\n- (.+?)\n","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/docusaurus-plugin-client-redirects/src/collectRedirects.ts","lineNumber":84,"sourceCode":"  return filterUnwantedRedirects(redirects, pluginContext);\n}\n\nfunction validateCollectedRedirects(\n  redirects: RedirectItem[],\n  pluginContext: PluginContext,\n) {\n  const redirectValidationErrors = redirects\n    .map((redirect) => {\n      try {\n        validateRedirect(redirect);\n        return undefined;\n      } catch (err) {\n        return (err as Error).message;\n      }\n    })\n    .filter(Boolean);\n  if (redirectValidationErrors.length > 0) {\n    throw new Error(\n      `Some created redirects are invalid:\n- ${redirectValidationErrors.join('\\n- ')}\n`,\n    );\n  }\n\n  const allowedToPaths = pluginContext.relativeRoutesPaths.map((p) =>\n    decodeURI(p),\n  );\n  const toPaths = redirects\n    .map((redirect) => redirect.to)\n    // We now allow \"to\" to contain any string\n    // We only do this \"broken redirect\" check from to that looks like pathnames\n    // note: we allow querystring/anchors\n    // See https://github.com/facebook/docusaurus/issues/6845\n    .map((to) => {\n      if (to.startsWith('/')) {\n        const url = URL.parse(to, 'https://example.com');","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/facebook/docusaurus/blob/3f483e80e326cc646b54b83d564b3f0c4881b9a6/packages/docusaurus-plugin-client-redirects/src/collectRedirects.ts#L66-L102","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Read the bulleted list in the error: each line is one validateRedirect failure message naming the bad redirect.","Fix each listed redirect's from/to to be valid absolute internal paths (leading slash).","If using createRedirects, ensure it only returns strings starting with '/' (or [] / '' for none).","Re-run the build to confirm no further validation errors."],"exampleFix":"// before\ncreateRedirects: (path) => 'old' + path,   // no leading slash\n// after\ncreateRedirects: (path) => '/old' + path,","handlingStrategy":"validation","validationCode":"function isValidRedirectPath(p: string): boolean {\n  return typeof p === 'string' && p.startsWith('/') && p.length > 1;\n}\n// validate createRedirects output before returning it:\nconst froms = (createRedirects?.(path) ?? []);\nconst arr = Array.isArray(froms) ? froms : [froms];\narr.forEach((f) => { if (!isValidRedirectPath(f)) throw new Error(`Bad redirect from: ${f}`); });","typeGuard":"const isRedirectItem = (r: unknown): r is {from: string; to: string} =>\n  !!r && typeof (r as any).from === 'string' && typeof (r as any).to === 'string'\n  && (r as any).from.startsWith('/') && (r as any).to.startsWith('/');","tryCatchPattern":null,"preventionTips":["Always return absolute internal paths (leading slash) from createRedirects.","Return [] or '' instead of invalid strings when no redirect applies.","Add a unit test for your createRedirects function covering edge-case inputs."],"tags":["plugin-client-redirects","redirects","validation","build"],"backgroundTag":null,"analyzedSha":"3f483e80e326cc646b54b83d564b3f0c4881b9a6","analyzedAt":"2026-08-12T13:25:04.382Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}