Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jest 21 Fails in CI with DuplicateHasteCandidatesError #4682

Closed
darkobits opened this issue Oct 12, 2017 · 7 comments · Fixed by americanexpress/amex-jest-preset#49
Closed

Comments

@darkobits
Copy link

Jest 21 Fails in CI with DuplicateHasteCandidatesError

Synopsis:

After upgrading to Jest 21.x from Jest 20.x, CI jobs began failing. Jest continues to work as expected in other environments.

Current Behavior:

When running in Jenkins 2, Jest fails with the following error:

FAIL <spec file>
  ● Test suite failed to run

    The name `chalk` 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. The platform is generic (no extension). You must
    delete or blacklist files until there remains only one of these:
    
    * `<Jenkins workspace folder>/npm-cache/chalk/1.1.3/package/package.json` (package)
    * `<Jenkins workspace folder>/npm-cache/chalk/2.1.0/package/package.json` (package)
      
    at DuplicateHasteCandidatesError (node_modules/jest-haste-map/build/module_map.js:150:5)

Expected Behavior:

Jest runs without error.

Additional Information:

  • This is only happening in our CI environment, Jenkins 2.
  • Our CI setup runs jobs inside a Docker container based on Ubuntu 14.04.5 LTS.
  • CI jobs run using NPM 4.0.1 and Node 6.11.1.
  • This issue cannot be reproduced on macOS 10.12.x running the same versions of Node, NPM, and Jest.
  • I believe this may be related to PR jest-haste-map: throw when trying to get a duplicated module #3976, which went out in Jest 21.0.0
  • I am particularly confused by this comment. If it is the case that third-parties should not be using jest-haste-map, and I never opted-in to using it, I do not understand why it is being used, at least in our CI environment.

Thanks for creating a great product, and thanks in advance for your help on this issue! ❤️

@cpojer
Copy link
Member

cpojer commented Oct 12, 2017

I recommend adding the npm-cache folder to modulePathIgnorePatterns because your config seems to include that in the Jest test run.

Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions. Thank you :)

@cpojer cpojer closed this as completed Oct 12, 2017
@jasonmorita
Copy link

I ran into the same issue on an older Node/npm combo. My package.json looks like this with both npm-cache and .npm for future proofing.

    "modulePathIgnorePatterns": [
      "npm-cache",
      ".npm"
    ]

@fledgling-vish
Copy link

This helped

@bdimitrovski
Copy link

I also experienced the same issue, but with almost all node modules. Symptomatically, this happens only in Jenkins, but not when I run tests locally.

Here is an excerpt from Jenkins console output:

at ModuleMap._assertNoDuplicates (node_modules/jest-haste-map/build/module_map.js:91:11)

FAIL .cache/yarn/v1/npm-agent-base-2.1.1-d6de10d5af6132d5bd692427d46fc538539094c7/test/test.js
  ● Test suite failed to run

    The name `jest-matcher-utils` 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. The platform is generic (no extension). You must delete or blacklist files until there remains only one of these:
    
      * `/var/lib/jenkins/workspace/st-jenkins-failed-tests-fix-WS7FGG4VPPPTO6OKQ7SR4PG7YVAHBV7ZHH6LHO5VZ6O4YGFMXTKA/.cache/yarn/v1/npm-jest-matcher-utils-22.4.0-d55f5faf2270462736bdf7c7485ee931c9d4b6a1/package.json` (package)
      * `/var/lib/jenkins/workspace/st-jenkins-failed-tests-fix-WS7FGG4VPPPTO6OKQ7SR4PG7YVAHBV7ZHH6LHO5VZ6O4YGFMXTKA/.cache/yarn/v1/npm-jest-matcher-utils-22.4.3-4632fe428ebc73ebc194d3c7b65d37b161f710ff/package.json` (package)
      
      
      at ModuleMap._assertNoDuplicates (node_modules/jest-haste-map/build/module_map.js:91:11)

FAIL .cache/yarn/v1/npm-functional-red-black-tree-1.0.1-1b0ab3bd553b2a0d6399d29c0e3ea0b252078327/test/test.js
  ● Test suite failed to run

    The name `jest-matcher-utils` 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. The platform is generic (no extension). You must delete or blacklist files until there remains only one of these:
    
      * `/var/lib/jenkins/workspace/st-jenkins-failed-tests-fix-WS7FGG4VPPPTO6OKQ7SR4PG7YVAHBV7ZHH6LHO5VZ6O4YGFMXTKA/.cache/yarn/v1/npm-jest-matcher-utils-22.4.0-d55f5faf2270462736bdf7c7485ee931c9d4b6a1/package.json` (package)
      * `/var/lib/jenkins/workspace/st-jenkins-failed-tests-fix-WS7FGG4VPPPTO6OKQ7SR4PG7YVAHBV7ZHH6LHO5VZ6O4YGFMXTKA/.cache/yarn/v1/npm-jest-matcher-utils-22.4.3-4632fe428ebc73ebc194d3c7b65d37b161f710ff/package.json` (package)
      
      
      at ModuleMap._assertNoDuplicates (node_modules/jest-haste-map/build/module_map.js:91:11)

and the list goes on.

What can cause this in the first place? I would like to know why I need to ignore all node modules, and what is the side effect of this in my particular case.

@infctr
Copy link

infctr commented Oct 18, 2018

@bdimitrovski
You're essentialy not ignoring your node_modules folder on CI environment, as all the packages are installed in your specified cache folder .cache/yarn, you can read that in your log

Try ignoring that foder in jest config:

"modulePathIgnorePatterns": [
      ".cache"
    ]

@raulfdm
Copy link

raulfdm commented Feb 14, 2019

Unfortunately [email protected] does not accept modulePathIgnorePatterns.

I'd tried --collectCoverageFrom=src/**/*.js --collectCoverageFrom=!.cache/. Didn't work. Then by adding as jest option at package.json, also didn't work.

Then finally I decided to instal react-app-rewired, add modulePathIgnorePatterns and now it working fine:

/* config-overrides.js */

module.exports = {
  jest(config) {
    config.modulePathIgnorePatterns = ['.cache'];
    return config;
  },
};

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
7 participants