{"record":{"id":"625fef0791565128","repo":"facebook/docusaurus","slug":"it-should-be-a-regexp-or-a-string-but-received","errorCode":null,"errorMessage":"it should be a RegExp or a string, but received ${from}","messagePattern":"it should be a RegExp or a string, but received (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/docusaurus-theme-search-algolia/src/validateThemeConfig.ts","lineNumber":56,"sourceCode":"    apiKey: Joi.string().required(),\n    indexName: Joi.string().required(),\n    searchParameters: Joi.object({\n      facetFilters: FacetFiltersSchema.optional(),\n    })\n      .default(DEFAULT_CONFIG.searchParameters)\n      .unknown(),\n    searchPagePath: Joi.alternatives()\n      .try(Joi.boolean().invalid(true), Joi.string())\n      .allow(null)\n      .default(DEFAULT_CONFIG.searchPagePath),\n    replaceSearchResultPathname: Joi.object({\n      from: Joi.custom((from) => {\n        if (typeof from === 'string') {\n          return RegExp.escape(from);\n        } else if (from instanceof RegExp) {\n          return from.source;\n        }\n        throw new Error(\n          `it should be a RegExp or a string, but received ${from}`,\n        );\n      }).required(),\n      to: Joi.string().required(),\n    }).optional(),\n    // Ask AI configuration (DocSearch v4 only)\n    askAi: Joi.alternatives()\n      .try(\n        // Simple string format (assistantId only)\n        Joi.string(),\n        // Full configuration object\n        Joi.object({\n          assistantId: Joi.string().required(),\n          // Optional Ask AI configuration\n          indexName: Joi.string().optional(),\n          apiKey: Joi.string().optional(),\n          appId: Joi.string().optional(),\n          searchParameters: Joi.object({","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/facebook/docusaurus/blob/3f483e80e326cc646b54b83d564b3f0c4881b9a6/packages/docusaurus-theme-search-algolia/src/validateThemeConfig.ts#L38-L74","documentation":"Thrown inside the Joi custom validator for themeConfig.algolia.replaceSearchResultPathname.from when the provided value is neither a string nor a RegExp. The validator normalizes string inputs via RegExp.escape and RegExp inputs via .source; anything else (number, object, array, undefined-but-required, boolean) is rejected with the received value interpolated into the message.","triggerScenarios":"Setting replaceSearchResultPathname: { from: 123, to: '' } or from: /pattern/ with a non-RegExp/non-string, or omitting 'from' where Joi marks it required, or passing an array/object.","commonSituations":"Typing from as a number; passing a string that should be a RegExp literal but quoted wrongly; copying config from JS that lost the RegExp object (e.g. JSON.stringify turned it into {}); misunderstanding the schema.","solutions":["Provide 'from' as a string (it will be escaped literally) or a RegExp object.","If you serialized config to JSON, restore RegExp objects after parsing (JSON has no RegExp type).","Match it with a 'to' string; both fields are required."],"exampleFix":"// before\nalgolia: { replaceSearchResultPathname: { from: 'docs/', to: '' } } // works, but if you used a number:\nalgolia: { replaceSearchResultPathname: { from: 0, to: '' } }\n// after\nalgolia: { replaceSearchResultPathname: { from: /^docs\\//, to: '' } }","handlingStrategy":"type-guard","validationCode":"const from = cfg.algolia?.replaceSearchResultPathname?.from;\nif (typeof from !== 'string' && !(from instanceof RegExp)) {\n  throw new Error('replaceSearchResultPathname.from must be string or RegExp');\n}","typeGuard":"const isStringOrRegExp = (v: unknown): v is string | RegExp =>\n  typeof v === 'string' || v instanceof RegExp;","tryCatchPattern":null,"preventionTips":["Avoid JSON-serializing configs that contain RegExp; rehydrate them after load.","Type the replaceSearchResultPathname option to string | RegExp to catch mistakes at compile time."],"tags":["algolia","search","theme-config","validation","regexp"],"backgroundTag":null,"analyzedSha":"3f483e80e326cc646b54b83d564b3f0c4881b9a6","analyzedAt":"2026-08-12T13:25:04.382Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}