{"id":"d00944bf685ca44c","repo":"babel/babel","slug":"msg-loc-must-be-a-undefined-a-boolean-a-stri-d00944","errorCode":null,"errorMessage":"${msg(loc)} must be a undefined, a boolean, a string/Function/RegExp or an array of those, got ${JSON.stringify(value as any)}","messagePattern":"(.+?) must be a undefined, a boolean, a string/Function/RegExp or an array of those, got (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/babel-core/src/config/validation/option-assertions.ts","lineNumber":326,"sourceCode":"\nexport function assertBabelrcSearch(\n  loc: OptionPath,\n  value: unknown,\n): BabelrcSearch | undefined {\n  if (value === undefined || typeof value === \"boolean\") {\n    return value;\n  }\n\n  if (Array.isArray(value)) {\n    value.forEach((item, i) => {\n      if (!checkValidTest(item)) {\n        throw new Error(\n          `${msg(access(loc, i))} must be a string/Function/RegExp.`,\n        );\n      }\n    });\n  } else if (!checkValidTest(value)) {\n    throw new Error(\n      `${msg(loc)} must be a undefined, a boolean, a string/Function/RegExp ` +\n        `or an array of those, got ${JSON.stringify(value as any)}`,\n    );\n  }\n  return value as BabelrcSearch;\n}\n\nexport function assertPluginList(\n  loc: OptionPath,\n  value: unknown[] | null | undefined,\n): PluginItem[] {\n  const arr = assertArray(loc, value);\n  if (arr) {\n    // Loop instead of using `.map` in order to preserve object identity\n    // for plugin array for use during config chain processing.\n    arr.forEach((item, i) => assertPluginItem(access(loc, i), item));\n  }\n  return arr as PluginItem[];","sourceCodeStart":308,"sourceCodeEnd":344,"githubUrl":"https://github.com/babel/babel/blob/06b6eae39da4ce0689fad64e2c48a6375a464208/packages/babel-core/src/config/validation/option-assertions.ts#L308-L344","documentation":"Thrown by assertBabelrcSearch when 'babelrcRoots' is a single non-array value that is not undefined, boolean, string, Function, or RegExp. The offending value is JSON.stringified in the message.","triggerScenarios":"babelrcRoots: { roots: ['a'] } (object); babelrcRoots: 42; babelrcRoots: null. The loc points at the option itself.","commonSituations":"Passing a config object expecting it to be merged; using a number expecting boolean semantics; legacy configs migrated from .babelrcrc roots.","solutions":["Pass true to enable all roots, false to disable, or a glob string/array of globs.","Convert object wrappers to a flat array of path strings.","Omit to use the default (babelrc disabled outside the root)."],"exampleFix":"// before\n{ babelrcRoots: { roots: ['packages/*'] } }\n// after\n{ babelrcRoots: ['packages/*'] }","handlingStrategy":"type-guard","validationCode":"function isBabelrcSearch(v) {\n  if (v === undefined || typeof v === 'boolean') return true;\n  if (typeof v === 'string' || typeof v === 'function' || v instanceof RegExp) return true;\n  if (Array.isArray(v)) return v.every(isBabelrcSearch);\n  return false;\n}\nif (!isBabelrcSearch(opts.babelrcRoots)) {\n  throw new Error('babelrcRoots invalid');\n}","typeGuard":"function isBabelrcSearch(v: unknown): boolean {\n  if (v === undefined || typeof v === 'boolean') return true;\n  if (typeof v === 'string' || typeof v === 'function' || v instanceof RegExp) return true;\n  if (Array.isArray(v)) return v.every(isBabelrcSearch);\n  return false;\n}","tryCatchPattern":"try {\n  babel.loadOptions(opts);\n} catch (e) {\n  if (e instanceof Error && /babelrcRoots must be/.test(e.message)) {\n    opts.babelrcRoots = true;\n    return babel.loadOptions(opts);\n  }\n  throw e;\n}","preventionTips":["Prefer boolean or array-of-globs for babelrcRoots.","Do not pass objects or numbers.","For monorepos, use ['packages/*'] patterns."],"tags":["config","babelrc","babelrcroots","monorepo","input-validation"],"analyzedSha":"06b6eae39da4ce0689fad64e2c48a6375a464208","analyzedAt":"2026-08-03T20:13:43.465Z","schemaVersion":2}