jestjs / jest

Delightful JavaScript Testing.
https://jestjs.io
MIT License
44.12k stars 6.44k forks source link

Installing Jest with NPM Breaks Start Script #8453

Closed mhyrka closed 5 years ago

mhyrka commented 5 years ago

🐛 Bug Report

After installing jest via npm install --save-dev jest, npm start breaks with the following message:

There might be a problem with the project dependency tree.
It is likely not a bug in Create React App, but something you need to fix locally.

The react-scripts package provided by Create React App requires a dependency:

  "jest": "23.6.0"

Don't try to install it manually: your package manager does it automatically.
However, a different version of jest was detected higher up in the tree:

  /mnt/c/Users/matthew.hyrka/ecompli-dashboard/node_modules/jest (version: 24.8.0)

Manually installing incompatible versions is known to cause hard-to-debug issues.

If you would prefer to ignore this check, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project.
That will permanently disable this message but you might encounter other issues.

To fix the dependency tree, try following the steps below in the exact order:

  1. Delete package-lock.json (not package.json!) and/or yarn.lock in your project folder.
  2. Delete node_modules in your project folder.
  3. Remove "jest" from dependencies and/or devDependencies in the package.json file in your project folder.
  4. Run npm install or yarn, depending on the package manager you use.

In most cases, this should be enough to fix the problem.
If this has not helped, there are a few other things you can try:

  5. If you used npm, install yarn (http://yarnpkg.com/) and repeat the above steps with it instead.
     This may help because npm has known issues with package hoisting which may get resolved in future versions.

  6. Check if /mnt/c/Users/matthew.hyrka/ecompli-dashboard/node_modules/jest is outside your project directory.
     For example, you might have accidentally installed something in your home folder.

  7. Try running npm ls jest in your project folder.
     This will tell you which other package (apart from the expected react-scripts) installed jest.

If nothing else helps, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project.
That would permanently disable this preflight check in case you want to proceed anyway.

P.S. We know this message is long but please read the steps above :-) We hope you find them helpful!

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! compli-dashboard@0.1.0 start: `REACT_APP_FORCE_DEVELOPMENT=Y REACT_APP_API_URL=http://ecompli.localwww/ecompli4/api/ react-scripts start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the compli-dashboard@0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/mhyrka/.npm/_logs/2019-05-10T19_36_00_134Z-debug.log

To Reproduce

Steps to reproduce the behavior: Here is my package.json.

{
  "version": "0.1.0",
  "private": true,
  "homepage": "./",
  "dependencies": {
    "@material-ui/core": "^3.9.2",
    "@material-ui/icons": "^3.0.2",
    "axios": "0.18.0",
    "browserslist": "^4.5.4",
    "classnames": "^2.2.6",
    "core-js": "^3.0.1",
    "dotenv": "^7.0.0",
    "downshift": "^3.1.5",
    "es6-shim": "^0.35.5",
    "keycode": "^2.2.0",
    "prop-types": "^15.6.2",
    "react": "^16.4.1",
    "react-app-polyfill": "^0.2.2",
    "react-cookie": "2.2.0",
    "react-dom": "^16.4.1",
    "react-media": "^1.8.0",
    "react-scripts": "^2.1.8",
    "react-toastify": "^4.5.2",
    "screenfull": "^4.0.0",
    "typeface-roboto": "0.0.54",
    "victory": "^32.0.2"
  },
  "scripts": {
    "start": "REACT_APP_FORCE_DEVELOPMENT=Y REACT_APP_API_URL=MY_URL react-scripts start",
    "build-staging": "REACT_APP_FORCE_DEVELOPMENT=Y REACT_APP_API_URL=MY_URL react-scripts build",
    "build": "REACT_APP_API_URL=MY_URL react-scripts build",
    "eject": "react-scripts eject",
    "generate-tasks": "node generate-dummy-tasks.js",
    "test": "jest"
  },
  "devDependencies": {
    "faker": "^4.1.0",
    "fs": "0.0.1-security",
    "jest": "^24.8.0"
  },
}

As stated, I installed jest using npm install --save-dev jest . It looks like that created a duplicate babel-jest entry in my package-lock.json with conflicting versions.

        "babel-jest": {
          "version": "24.8.0",
          "resolved": "https://registry.npmjs.org/babel-jest/-/babel-jest-24.8.0.tgz",
          "integrity": "sha512-+5/kaZt4I9efoXzPlZASyK/lN9qdRKmmUav9smVc0ruPQD7IsfucQ87gpOE8mn2jbDuS6M/YOW6n3v9ZoIfgnw==",
          "dev": true,
          "requires": {
            "@jest/transform": "^24.8.0",
            "@jest/types": "^24.8.0",
            "@types/babel__core": "^7.1.0",
            "babel-plugin-istanbul": "^5.1.0",
            "babel-preset-jest": "^24.6.0",
            "chalk": "^2.4.2",
            "slash": "^2.0.0"
          },
          "dependencies": {
            "chalk": {
              "version": "2.4.2",
              "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz",
              "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==",
              "dev": true,
              "requires": {
                "ansi-styles": "^3.2.1",
                "escape-string-regexp": "^1.0.5",
                "supports-color": "^5.3.0"
              }
            }
          }
        }

&&

    "babel-jest": {
      "version": "23.6.0",
      "resolved": "https://registry.npmjs.org/babel-jest/-/babel-jest-23.6.0.tgz",
      "integrity": "sha512-lqKGG6LYXYu+DQh/slrQ8nxXQkEkhugdXsU6St7GmhVS7Ilc/22ArwqXNJrf0QaOBjZB0360qZMwXqDYQHXaew==",
      "requires": {
        "babel-plugin-istanbul": "^4.1.6",
        "babel-preset-jest": "^23.2.0"
      }
    },

I've gone through the steps detailed in the error message, but then I don't have jest anymore and its back to square one.

Expected behavior

Link to repl or repo (highly encouraged)

Please provide either a repl.it demo or a minimal repository on GitHub.

Issues without a reproduction link are likely to stall.

Run npx envinfo --preset jest

Paste the results here:

$ npx envinfo --preset jest
npx: installed 1 in 3.236s

  System:
    OS: Windows 10
    CPU: (8) x64 Intel(R) Core(TM) i7-8650U CPU @ 1.90GHz
  Binaries:
    Node: 10.15.3 - C:\Program Files\nodejs\node.EXE
    npm: 6.4.1 - C:\Program Files\nodejs\npm.CMD
SimenB commented 5 years ago

CRA comes with jest out of the box, you don't need to install it yourself. So just remove all mention of Jest in your package.json's devDependencies, and you should be good

CRA@3 comes with jest 24

github-actions[bot] commented 3 years ago

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.