{"record":{"id":"d80cd4f9c73b950d","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${duplicatesList}","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(.+?)","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/8e6d128e4a278059ecddecaa97400b04c8ae5fd9/packages/jest-haste-map/src/ModuleMap.ts#L173-L209","documentation":"Thrown as `DuplicateHasteCandidatesError` when module resolution finds multiple files or packages providing the same haste module name for the same platform. Jest's haste map requires names to be unique per platform; when duplicates exist, it cannot decide which file to resolve and lists all candidates.","triggerScenarios":"Two files declaring the same `@providesModule` name, two `package.json` files with the same `name` in different directories both reachable by the haste map, or platform-specific files (e.g. `Foo.js` and `Foo.ios.js`) that resolve to the same generic platform. The error is thrown from `_assertNoDuplicates` during `getModule`/`getPackage`.","commonSituations":"React Native projects where `@providesModule` annotations collide. Monorepo with multiple packages sharing the same npm name. Accidental file duplication (copy-paste). A symlink creating a second path to the same haste-decorated file. Migrating to haste and having leftover declarations.","solutions":["Read the error — it lists all conflicting file paths and their types (module/package).","Delete, rename, or exclude one of the duplicate files so only one remains for that name+platform.","Add the conflicting path to `modulePathIgnorePatterns` or ` haste.retainAllFiles: false` scope.","If duplicates come from node_modules symlinks in a monorepo, configure `haste.enableSymlinks` or dedupe with the package manager.","Rename the `@providesModule` declaration in one of the files."],"exampleFix":"// before: two files both declare\n// src/Foo.js\n/** @providesModule Foo */\n// src/components/Foo.js  (accidental copy)\n/** @providesModule Foo */\n\n// after: remove the duplicate or rename it\n// src/components/Foo.js\n/** @providesModule NewFoo */","handlingStrategy":"validation","validationCode":"// Scan for duplicate @providesModule declarations before running Jest\nconst fs = require('fs');\nconst path = require('path');\nfunction findDuplicateHasteNames(rootDir) {\n  const names = new Map();\n  function walk(dir) {\n    for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {\n      if (entry.name === 'node_modules') continue;\n      const full = path.join(dir, entry.name);\n      if (entry.isDirectory()) { walk(full); }\n      else if (/\\.js$/.test(entry.name)) {\n        const content = fs.readFileSync(full, 'utf8');\n        const match = content.match(/@providesModule\\s+(\\S+)/);\n        if (match) {\n          if (names.has(match[1])) {\n            throw new Error(`Duplicate @providesModule ${match[1]}: ${names.get(match[1])} and ${full}`);\n          }\n          names.set(match[1], full);\n        }\n      }\n    }\n  }\n  walk(rootDir);\n}","typeGuard":null,"tryCatchPattern":"try {\n  const modulePath = hasteMap.getModule(name, platform);\n  if (!modulePath) throw new Error(`Cannot resolve module: ${name}`);\n} catch (e) {\n  if (e.constructor.name === 'DuplicateHasteCandidatesError') {\n    console.error('Haste name collision:', e.hasteName, e.duplicatesSet);\n    // Guide user to deduplicate\n  }\n  throw e;\n}","preventionTips":["Run a duplicate-haste-names scan script before CI in React Native projects.","Use unique package.json names across all packages in a monorepo.","Avoid copy-pasting files that contain @providesModule declarations.","Add duplicate detection to a pre-commit hook or lint step.","Use modulePathIgnorePatterns to exclude generated/temp directories from the haste map."],"tags":["jest-haste-map","duplicate-modules","module-resolution","configuration","monorepo"],"backgroundTag":null,"analyzedSha":"8e6d128e4a278059ecddecaa97400b04c8ae5fd9","analyzedAt":"2026-08-10T18:11:27.960Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}