Reference for validateOptions and validateThemeConfig static methods used to validate and normalize Docusaurus plugin options and theme configuration with Joi.
Use this file to discover all available pages before exploring further.
Static methods are attached to the plugin module’s constructor function itself rather than to any plugin instance. Docusaurus calls them before it initializes plugins, which means they run even before the plugin constructor receives its context and options arguments. Their main responsibility is to validate user-supplied configuration and return a canonical, normalized form that the rest of the plugin can rely on.
A function that accepts a Joi schema and the raw options, then returns validated and normalized options. It automatically handles Joi errors and formats them as useful error messages.
Use import {Joi} from '@docusaurus/utils-validation' rather than installing Joi directly. This ensures you use the exact Joi version Docusaurus expects and avoids version conflicts that produce confusing validation errors.
If you prefer not to use Joi, you can validate manually and throw an Error for invalid input:
export function validateOptions({options, validate}) { if (!options.path || typeof options.path !== 'string') { throw new Error( '[my-plugin] The "path" option is required and must be a string.', ); } return { path: options.path, routeBasePath: options.routeBasePath ?? 'docs', };}
When validateOptions is not exported, the raw user-supplied options are passed directly to the plugin constructor without any normalization. Always export validateOptions to catch configuration mistakes early and provide meaningful error messages.
Called before plugin initialization to validate and normalize the themeConfig field from docusaurus.config.js. Returns the validated and normalized theme config.
The raw themeConfig object from the user’s docusaurus.config.js. Only validate the keys your theme or plugin owns — ignore the rest so that other plugins’ keys are not accidentally stripped.
Static methods run in this order before any plugin instance is created:
validateOptions — called once per plugin instance with the raw user options.
validateThemeConfig — called once per plugin module with the site’s themeConfig.
Both methods run before the plugin constructor is called. This means the constructor always receives validated, normalized values.
When to throw vs. return from validation
The validate helper throws a ValidationError automatically when the Joi schema fails. If you validate without Joi, throw a plain Error with a descriptive message that names the plugin and the offending option. Never silently swallow bad input — users need to know what is wrong and where.