facebook/flow · error · Error
flow-remove-types: includes and excludes must be RegExp or p
Error message
flow-remove-types: includes and excludes must be RegExp or path strings. Got: ${pattern} What it means
flow-remove-types/register converts each pattern in includes/excludes into a RegExp: strings get '.' escaped and '*' widened to '.*' (and are prefixed with a leading '/'), and anything with a .test function is used as-is. This error is the validation branch for patterns that are neither strings nor RegExp-likes, thrown at startup of the require hook rather than at transform time.
Source
Thrown at packages/flow-remove-types/register.js:73
// Given a null | string | RegExp | any, returns null | Regexp or throws a
// more helpful error.
function regexpPattern(pattern) {
if (!pattern) {
return pattern;
}
// A very simplified glob transform which allows passing legible strings like
// "myPath/*.js" instead of a harder to read RegExp like /\/myPath\/.*\.js/.
if (typeof pattern === 'string') {
pattern = pattern.replace(/\./g, '\\.').replace(/\*/g, '.*');
if (pattern[0] !== '/') {
pattern = '/' + pattern;
}
return new RegExp(pattern);
}
if (typeof pattern.test === 'function') {
return pattern;
}
throw new Error(
'flow-remove-types: ' +
'includes and excludes must be RegExp or path strings. Got: ' +
pattern,
);
}
View on GitHub (pinned to d1341dac89)
Solutions
- Make every entry a path string like 'src/*.js' or a RegExp such as new RegExp('/src/.*[.]js$')
- Wrap the pattern list in an explicit array so a bare string is not iterated per character
- Validate config types at load time (e.g. a zod or joi schema) before handing them to the register hook
Example fix
// before
require('flow-remove-types/register')({includes: 'lib/*.js'}); // string iterated -> junk entries
// after
require('flow-remove-types/register')({includes: ['lib/*.js']}); Defensive patterns
Strategy: type-guard
Validate before calling
const isPattern = (p) => typeof p === 'string' || (p != null && typeof p.test === 'function');
function assertPatterns(list) {
for (const p of list) {
if (!isPattern(p)) throw new TypeError('Pattern must be string or RegExp, got ' + typeof p);
}
} Type guard
const isValidPattern = (p) => typeof p === 'string' || (p != null && typeof p === 'object' && typeof p.test === 'function');
Prevention
- Always pass includes/excludes as arrays of strings or RegExps; never a bare string or nested arrays
- Validate env- or JSON-sourced config values with a schema before the register hook reads them
- Remember string patterns are matched against a leading '/', so write 'src/*.js' rather than a bare glob
When it happens
Trigger: Passing a number, boolean, null, array, or a plain object (e.g. a micromatch or parse-glob result) in the includes or excludes array of require('flow-remove-types/register')({includes: [...]}) or the equivalent CLI flags.
Common situations: Config parsed from JSON, YAML, or env vars where a pattern ends up typed as a number or list; passing glob objects from another library; typos like includes: 'src/*.js' where a bare string is iterated char-by-char, producing junk patterns that eventually hit this throw.
Related errors
- Unsupported .flowconfig option `log.file`. The VS Code exten
- flow option must be "all" or "detect"
- sourceType option must be "script", "module", or "unambiguou
- flow-remove-types: the "checkPragma" option has been replace
AI-assisted analysis of facebook/flow@d1341dac89 (2026-08-17).
Data as JSON: /api/errors/80935009ba403946.
Report an issue: GitHub.