Skip to content
Latchkey

Jest "jest-haste-map: duplicate manual mock found" / Naming Collision

Jest’s Haste module map requires each module name to be unique. The error means two files claim the same name - usually a duplicated package.json "name" in a build/output folder, or two __mocks__ files for the same module.

What this error means

Jest prints "jest-haste-map: Haste module naming collision" (or "duplicate manual mock found") listing two file paths that share a name. One of the paths is frequently a dist/build copy that should never have been scanned.

Jest output
jest-haste-map: Haste module naming collision: my-pkg

  The following files share their name; please adjust your hasteImpl:
    * <rootDir>/package.json
    * <rootDir>/dist/package.json

Common causes

A build output copy is scanned alongside the source

A dist/build/coverage folder contains a copied package.json (or duplicated modules). Jest’s Haste map sees the same name twice and reports a collision.

Two manual mocks for the same module

Two __mocks__/<name>.js files (in different folders) target the same module name, so Jest cannot decide which manual mock to use.

How to fix it

Ignore build output in modulePathIgnorePatterns

Exclude generated folders so their copied files never enter the Haste map.

jest.config.js
// jest.config.js
module.exports = {
  modulePathIgnorePatterns: ['<rootDir>/dist/', '<rootDir>/build/'],
};

Resolve duplicate manual mocks

  1. Keep a single __mocks__/<name>.js per module name.
  2. Clean stale build output before running Jest (rm -rf dist in CI).
  3. Re-run once with --no-cache so a stale Haste map is rebuilt.

How to prevent it

  • Add dist/build/coverage to modulePathIgnorePatterns.
  • Clean generated output before test runs in CI.
  • Keep exactly one manual mock per module name.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →