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-haste-map: Haste module naming collision: my-pkg
The following files share their name; please adjust your hasteImpl:
* <rootDir>/package.json
* <rootDir>/dist/package.jsonCommon 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
module.exports = {
modulePathIgnorePatterns: ['<rootDir>/dist/', '<rootDir>/build/'],
};Resolve duplicate manual mocks
- Keep a single
__mocks__/<name>.jsper module name. - Clean stale build output before running Jest (
rm -rf distin CI). - Re-run once with
--no-cacheso a stale Haste map is rebuilt.
How to prevent it
- Add
dist/build/coveragetomodulePathIgnorePatterns. - Clean generated output before test runs in CI.
- Keep exactly one manual mock per module name.