facebook/docusaurus · error · Error
${JSON.stringify(redirect)} => Validation error: ${error.mes
Error message
${JSON.stringify(redirect)} => Validation error: ${error.message} What it means
Thrown by validateRedirect when a redirect object fails Joi schema validation (the 'from' field must be a valid pathname and 'to' must be a string, both required). The error message embeds the offending redirect via JSON.stringify so you can identify which entry is malformed. It uses abortEarly:true, so only the first problem is reported.
Source
Thrown at packages/docusaurus-plugin-client-redirects/src/redirectValidation.ts:24
*/
import {Joi, PathnameSchema} from '@docusaurus/utils-validation';
import type {RedirectItem} from './types';
const RedirectSchema = Joi.object<RedirectItem>({
from: PathnameSchema.required(),
to: Joi.string().required(),
});
export function validateRedirect(redirect: RedirectItem): void {
const {error} = RedirectSchema.validate(redirect, {
abortEarly: true,
convert: false,
});
if (error) {
// Tells the user which redirect is the problem!
throw new Error(
`${JSON.stringify(redirect)} => Validation error: ${error.message}`,
);
}
}
View on GitHub (pinned to 3f483e80e3)
Solutions
- Inspect the printed JSON in the message: it shows the exact object that failed.
- Ensure each redirect has a non-empty 'from' (leading slash, valid URL path) and a string 'to'.
- Validate your redirects array with RedirectSchema before passing to the plugin.
Example fix
// before
redirects: [{ from: '', to: '/docs/intro' }, { form: '/a', to: '/b' }]
// after
redirects: [{ from: '/old', to: '/docs/intro' }, { from: '/a', to: '/b' }] Defensive patterns
Strategy: validation
Validate before calling
import {RedirectSchema} from '@docusaurus/plugin-client-redirects';
// or replicate: Joi.object({ from: Joi.string().required(), to: Joi.string().required() })
const {error} = RedirectSchema.validate(redirect);
if (error) throw new Error(`Bad redirect ${JSON.stringify(redirect)}: ${error.message}`); Type guard
const isRedirect = (r: unknown): r is {from: string; to: string} =>
typeof r === 'object' && r !== null &&
typeof (r as any).from === 'string' && (r as any).from.startsWith('/') &&
typeof (r as any).to === 'string' && (r as any).to.length > 0; Prevention
- Lint your docusaurus.config.js redirects array with the schema in CI.
- Keep redirects in a dedicated JSON file and validate it before import.
When it happens
Trigger: Calling validateRedirect with a redirect missing 'from' or 'to', having an empty pathname, or having 'from' fail PathnameSchema (e.g. empty string or non-string). Happens during build when the client-redirects plugin processes its 'redirects' option array.
Common situations: Typos in docusaurus.config.js redirects option (writing `form:` instead of `from:`, omitting `to:`), passing a redirect where `from` is an empty string, or copying example config that used a placeholder. Also from a redirects JSON file imported with wrong key names.
Related errors
- Swizzle config does not match expected schema: ${result.erro
- VCS config preset name '${input}' is not valid.
- ${formattedError}
- Unexpected "reportingSeverity" value: ${reportingSeverity}.
- Some created redirects are invalid: - ${redirectValidationEr
AI-assisted analysis of facebook/docusaurus@3f483e80e3 (2026-08-12).
Data as JSON: /api/errors/b120d051129f85c4.
Report an issue: GitHub.