{"record":{"id":"80935009ba403946","repo":"facebook/flow","slug":"flow-remove-types-includes-and-excludes-must-be-r","errorCode":null,"errorMessage":"flow-remove-types: includes and excludes must be RegExp or path strings. Got: ${pattern}","messagePattern":"flow-remove-types: includes and excludes must be RegExp or path strings\\. Got: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/flow-remove-types/register.js","lineNumber":73,"sourceCode":"// Given a null | string | RegExp | any, returns null | Regexp or throws a\n// more helpful error.\nfunction regexpPattern(pattern) {\n  if (!pattern) {\n    return pattern;\n  }\n  // A very simplified glob transform which allows passing legible strings like\n  // \"myPath/*.js\" instead of a harder to read RegExp like /\\/myPath\\/.*\\.js/.\n  if (typeof pattern === 'string') {\n    pattern = pattern.replace(/\\./g, '\\\\.').replace(/\\*/g, '.*');\n    if (pattern[0] !== '/') {\n      pattern = '/' + pattern;\n    }\n    return new RegExp(pattern);\n  }\n  if (typeof pattern.test === 'function') {\n    return pattern;\n  }\n  throw new Error(\n    'flow-remove-types: ' +\n      'includes and excludes must be RegExp or path strings. Got: ' +\n      pattern,\n  );\n}\n","sourceCodeStart":55,"sourceCodeEnd":79,"githubUrl":"https://github.com/facebook/flow/blob/f88ac94bcf6992f5d5a158854d94613ebb92c6e6/packages/flow-remove-types/register.js#L55-L79","documentation":"Thrown by flow-remove-types/register's `regexpPattern` helper while deciding whether a file should be transformed. The `includes`/`include` and `excludes`/`exclude` options accept only a string (treated as a very simplified glob: `.` is escaped and `*` becomes `.*`, optionally prefixed with `/`) or a RegExp-like object exposing a `.test` function. Anything else - arrays, numbers, booleans, plain objects - hits the final throw.","triggerScenarios":"Calling `require('flow-remove-types/register')({includes: ['src/**/*.js']})` (an array, as used by babel/jest configs), `{excludes: true}`, or `{includes: {test: 'src'}}`. The error surfaces lazily on the first `require()` of a .js/.jsx/.mjs/.cjs/.flow/.es6 file because that is when the pirates hook matcher runs.","commonSituations":"Copy-pasting an array-of-globs config from babel-plugin or jest transform settings; passing a minimatch pattern expecting full glob semantics (`?`, `**` special-casing); passing `excludes: undefined` vs `excludes: null` confusion (null is fine - it disables the default /node_modules/ exclusion).","solutions":["Pass a single string glob (e.g. `'src/*.js'`) or a single RegExp (e.g. `/\\/src\\/.*\\.js$/`).","If you have an array of globs, combine them into one RegExp: `new RegExp(globs.map(g => g.replace(/\\./g,'\\\\.').replace(/\\*/g,'.*')).join('|'))`.","Do not use `?` or character classes in string globs - only `*` is expanded; switch to RegExp for anything richer.","Remember `excludes` defaults to /\\/node_modules\\//; pass `excludes: null` to transform node_modules too."],"exampleFix":"// before\nrequire('flow-remove-types/register')({\n  includes: ['src/**/*.js', 'lib/*.js'],\n});\n\n// after\nrequire('flow-remove-types/register')({\n  includes: /(\\/src\\/|\\/lib\\/).*\\.js$/,\n});","handlingStrategy":"validation","validationCode":"function isValidPattern(p) {\n  return p == null || typeof p === 'string' || p instanceof RegExp;\n}\n\nfunction normalizePatterns(globs) {\n  // combine array-of-globs into the single RegExp the register hook accepts\n  if (Array.isArray(globs)) {\n    return new RegExp(globs.map(g =>\n      '/' + g.replace(/\\./g, '\\\\.').replace(/\\*/g, '.*')\n    ).join('|'));\n  }\n  return globs;\n}\n\nif (!isValidPattern(opts.includes) || !isValidPattern(opts.excludes)) {\n  throw new TypeError('includes/excludes must be a string glob or RegExp');\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Remember only string-glob or single RegExp are accepted; arrays are not.","The error is lazy - it fires on the first require() of a JS file, so validate options eagerly at startup.","String globs only expand '*' to '.*'; use RegExp for anything else.","Pass excludes: null (not undefined) when you want node_modules transformed."],"tags":["flow","flow-remove-types","require-hook","glob","regexp","config"],"backgroundTag":"invalid-config-value","analyzedSha":"f88ac94bcf6992f5d5a158854d94613ebb92c6e6","analyzedAt":"2026-08-20T10:41:37.992Z","contentChangedAt":"2026-08-20T10:41:37.992Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}