{"id":"4f5ea2458c0761e1","repo":"jestjs/jest","slug":"the-name-name-was-looked-up-in-the-haste-modu","errorCode":null,"errorMessage":"The name `${name}` was looked up in the Haste module map. It cannot be resolved, because there exists several different files, or packages, that provide a module for that particular name and platform. ${platformMessage} You must delete or exclude files until there remains only one of these:\n\n  * `${dupFilePath}` (${getTypeMessage(dupFileType)})\n","messagePattern":"The name `(.+?)` was looked up in the Haste module map\\. It cannot be resolved, because there exists several different files, or packages, that provide a module for that particular name and platform\\. (.+?) You must delete or exclude files until there remains only one of these:\n\n  \\* `(.+?)` \\((.+?)\\)\n","errorType":"exception","errorClass":"DuplicateHasteCandidatesError","httpStatus":null,"severity":"error","filePath":"packages/jest-haste-map/src/ModuleMap.ts","lineNumber":191,"sourceCode":"  private _assertNoDuplicates(\n    name: string,\n    platform: string,\n    supportsNativePlatform: boolean,\n    relativePathSet: DuplicatesSet | null,\n  ) {\n    if (relativePathSet == null) {\n      return;\n    }\n    // Force flow refinement\n    const previousSet = relativePathSet;\n    const duplicates = new Map();\n\n    for (const [relativePath, type] of previousSet) {\n      const duplicatePath = fastPath.resolve(this._raw.rootDir, relativePath);\n      duplicates.set(duplicatePath, type);\n    }\n\n    throw new DuplicateHasteCandidatesError(\n      name,\n      platform,\n      supportsNativePlatform,\n      duplicates,\n    );\n  }\n\n  static create(rootDir: string): ModuleMap {\n    return new ModuleMap({\n      duplicates: new Map(),\n      map: new Map(),\n      mocks: new Map(),\n      rootDir,\n    });\n  }\n}\n\nclass DuplicateHasteCandidatesError extends Error {","sourceCodeStart":173,"sourceCodeEnd":209,"githubUrl":"https://github.com/jestjs/jest/blob/f49721c78e195558b40913977c9230f5b7f559d8/packages/jest-haste-map/src/ModuleMap.ts#L173-L209","documentation":"jest-haste-map builds a haste-id → file map for platforms/generic resolution. When a single haste name resolves to more than one file for the same platform, `_assertNoDuplicates` throws DuplicateHasteCandidatesError (ModuleMap.ts:191) listing every conflicting path, because the resolver cannot pick one deterministically. This is the classic Jest 'duplicate manual mocks / haste collision' failure.","triggerScenarios":"Two files declare the same haste module name (e.g. `@providesModule Foo`) for the same platform; a manual mock in `__mocks__` collides with a real module of the same name; an npm dependency and a local file share a haste id; platform-specific files (`.ios.js`/`.android.js`) collide on the generic platform.","commonSituations":"Adding a manual mock that duplicates an installed package name; monorepo with two packages providing the same module; symlinking node_modules so a package is crawled twice; leftover generated files sharing a name; RN-style haste modules colliding after a dependency addition.","solutions":["Read the listed duplicate paths and delete or rename one of them.","Add `modulePathIgnorePatterns` / ` haste.providesModuleNodeModules` / `roots` config so only one copy is crawled.","If a manual mock collides with a real package, remove the `__mocks__/<name>.js` entry or scope it via configuration.","For monorepos, ensure each package's `__mocks__` is not globally visible; use `projects`/workspaces config to isolate.","If a symlink is the cause, dedupe with yarn `resolutions` or npm `overrides`."],"exampleFix":"// before: both __mocks__/db.js and node_modules/db exist\ntestEnvironment: 'node'\n\n// after: remove the global manual mock and scope it\n// delete __mocks__/db.js, instead mock at test level:\njest.mock('db', () => ({ query: jest.fn() }));","handlingStrategy":"validation","validationCode":"// preflight: scan for haste name collisions before running\nconst seen = new Map();\nfor (const f of crawl('src')) {\n  const name = readProvidesModuleName(f);\n  if (name && seen.has(name)) throw new Error(`duplicate haste id ${name}: ${seen.get(name)} vs ${f}`);\n  if (name) seen.set(name, f);\n}","typeGuard":"const hasNoHasteCollision = (map: Map<string, string>) => map.size === new Set(map.values()).size;","tryCatchPattern":null,"preventionTips":["Avoid @providesModule except where necessary; prefer explicit imports.","Scope __mocks__ per project in monorepos.","Configure modulePathIgnorePatterns to exclude duplicate roots.","Dedupe node_modules via resolutions/overrides."],"tags":["jest-haste-map","module-resolution","duplicate","haste"],"analyzedSha":"f49721c78e195558b40913977c9230f5b7f559d8","analyzedAt":"2026-08-03T20:16:28.571Z","schemaVersion":2}