{"id":"176f1dc3c7cd710f","repo":"jestjs/jest","slug":"jest-haste-map-the-ignorepattern-option-must-be","errorCode":null,"errorMessage":"jest-haste-map: the `ignorePattern` option must be a RegExp","messagePattern":"jest-haste-map: the `ignorePattern` option must be a RegExp","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/jest-haste-map/src/index.ts","lineNumber":254,"sourceCode":"      retainAllFiles: options.retainAllFiles,\n      rootDir: options.rootDir,\n      roots: [...new Set(options.roots)],\n      skipPackageJson: !!options.skipPackageJson,\n      throwOnModuleCollision: !!options.throwOnModuleCollision,\n      useWatchman: options.useWatchman ?? true,\n      watch: !!options.watch,\n      workerThreads: options.workerThreads,\n    };\n    this._console = options.console || globalThis.console;\n\n    if (options.ignorePattern) {\n      if (options.ignorePattern instanceof RegExp) {\n        this._options.ignorePattern = new RegExp(\n          `${options.ignorePattern.source}|${VCS_DIRECTORIES}`,\n          options.ignorePattern.flags,\n        );\n      } else {\n        throw new TypeError(\n          'jest-haste-map: the `ignorePattern` option must be a RegExp',\n        );\n      }\n    } else {\n      this._options.ignorePattern = new RegExp(VCS_DIRECTORIES);\n    }\n\n    if (this._options.enableSymlinks && this._options.useWatchman) {\n      throw new Error(\n        'jest-haste-map: enableSymlinks config option was set, but ' +\n          'is incompatible with watchman.\\n' +\n          'Set either `enableSymlinks` to false or `useWatchman` to false.',\n      );\n    }\n\n    this._ignoreFn = buildIgnoreMatcher(\n      this._options.ignorePattern,\n      this._options.retainAllFiles,","sourceCodeStart":236,"sourceCodeEnd":272,"githubUrl":"https://github.com/jestjs/jest/blob/f49721c78e195558b40913977c9230f5b7f559d8/packages/jest-haste-map/src/index.ts#L236-L272","documentation":"The HasteMap constructor validates the `ignorePattern` option: if provided it MUST be a RegExp instance. The library merges your pattern with VCS directory patterns to build a combined matcher, which only works on a RegExp source/flags. A string, array, glob, or any other type is rejected up front rather than producing silently-wrong ignore behavior later.","triggerScenarios":"Calling HasteMap.create({...options, ignorePattern: <not a RegExp>}) where the value is a string (e.g. 'node_modules'), an array of globs, a function, or undefined-but-truthy. The branch at index.ts:247 enters because ignorePattern is truthy, then the `instanceof RegExp` check at line 248 fails, hitting the throw at line 254.","commonSituations":"Migrating from a config that accepted string ignore patterns; passing a glob string from a shared config object; tooling that reads .gitignore-style strings and forwards them as ignorePattern; jest-config wiring that forwards haste.ignorePattern without converting to RegExp.","solutions":["Pass a RegExp: wrap your pattern with new RegExp(...) before handing it to HasteMap/Jest.","If you have multiple patterns, combine them with alternation into one RegExp, e.g. new RegExp('node_modules|build|dist').","If the value originates from jest config `haste`, ensure the upstream config layer (jest-config → HasteMap.Options) normalizes it to a RegExp.","Omit ignorePattern entirely to accept the default VCS-directory-only ignore behavior."],"exampleFix":"// before\nHasteMap.create({ ignorePattern: 'node_modules', ... });\n\n// after\nHasteMap.create({ ignorePattern: /node_modules/, ... });","handlingStrategy":"type-guard","validationCode":"if (options.ignorePattern != null && !(options.ignorePattern instanceof RegExp)) {\n  throw new TypeError('ignorePattern must be a RegExp; got ' + typeof options.ignorePattern);\n}","typeGuard":"function isRegExp(v: unknown): v is RegExp {\n  return v instanceof RegExp;\n}\n// usage:\nif (options.ignorePattern != null && !isRegExp(options.ignorePattern)) {\n  // normalize or throw before passing to HasteMap\n  options.ignorePattern = new RegExp(String(options.ignorePattern));\n}","tryCatchPattern":null,"preventionTips":["Always construct ignorePattern with new RegExp(...) in config code.","If accepting user config strings, normalize to RegExp at the config boundary.","Add a unit test asserting ignorePattern is a RegExp after config normalization."],"tags":["haste-map","config","validation","typescript"],"analyzedSha":"f49721c78e195558b40913977c9230f5b7f559d8","analyzedAt":"2026-08-03T20:16:28.571Z","schemaVersion":2}