{"record":{"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":"validation","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/8e6d128e4a278059ecddecaa97400b04c8ae5fd9/packages/jest-haste-map/src/index.ts#L236-L272","documentation":"jest-haste-map accepts an `ignorePattern` option to exclude file paths from the crawl. The constructor enforces that it MUST be a RegExp instance; any other type (string, array, glob) is rejected with a TypeError before any work begins. Internally the RegExp source is merged with VCS directory patterns, so a non-RegExp cannot be processed.","triggerScenarios":"Passing `HasteMap.create({ ignorePattern: 'node_modules' })` or any non-RegExp value. The constructor checks `options.ignorePattern instanceof RegExp` at index.ts:248; when it fails, the TypeError is thrown at line 254.","commonSituations":"A Jest config or custom haste-map caller passes a glob string (e.g. '**/fixtures/**') instead of a RegExp. Also happens when migrating from an older config format that accepted strings, or when a build tool forwards user input without converting it to RegExp.","solutions":["Wrap your ignore pattern in `new RegExp(...)`: `ignorePattern: new RegExp('node_modules|fixtures')`.","If using Jest CLI `--hasteIgnorePattern`, ensure the downstream code compiles the string to a RegExp before reaching HasteMap.","Omit `ignorePattern` entirely if you only need VCS exclusion — the default already ignores `.git`, `.hg`, `.sl`."],"exampleFix":"// before\nHasteMap.create({ ..., ignorePattern: '**/fixtures/**' });\n// after\nHasteMap.create({ ..., ignorePattern: /fixtures/ });","handlingStrategy":"type-guard","validationCode":"// Ensure ignorePattern is a RegExp before passing to HasteMap.\nfunction toIgnorePattern(value: unknown): RegExp | undefined {\n  if (value === undefined) return undefined;\n  if (value instanceof RegExp) return value;\n  if (typeof value === 'string') return new RegExp(value);\n  throw new TypeError(`ignorePattern must be a RegExp or string, got ${typeof value}`);\n}","typeGuard":"function isRegExp(value: unknown): value is RegExp {\n  return value instanceof RegExp;\n}","tryCatchPattern":null,"preventionTips":["Always wrap ignorePattern strings in `new RegExp(...)` at the config boundary.","Add a unit test asserting the config object's ignorePattern is a RegExp.","Document the RegExp-only requirement in your project's Jest config docs."],"tags":["configuration","validation","typescript","regex"],"backgroundTag":null,"analyzedSha":"8e6d128e4a278059ecddecaa97400b04c8ae5fd9","analyzedAt":"2026-08-10T18:11:27.960Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}