简体   繁体   中英

babel-jest version conflict in react + node application

Im trying to run jest tests on server side of my application but the babel-jest version is conflicting with react's babel-jest version.

and when i run my application i get this error.

when i do 'npm ls babel-jest' i get this

babel-jest@24.9.0 -- jest@26.0.1 -- @jest/core@26.0.1 -- jest-config@26.0.1 -- babel-jest@26.0.1

Follow all of the steps that the error output gave your, but instead of the step 3 that's given (remove it from dependencies), do this:

  1. go into package.json , locate jest in dependencies and/or devDependencies , and replace the version number you find with 24.9.0
cmds-ui-operations@0.1.2 /builds/ielts-cmds/IELTS-CMDS-ui-grp/cmds-ui-operations
+-- react-scripts@3.4.1
| +-- babel-jest@24.9.0
| `-- jest@24.9.0
|   `-- jest-cli@24.9.0
|     `-- jest-config@24.9.0
|       `-- babel-jest@24.9.0 deduped
`-- ts-jest@26.4.3
  `-- jest@26.6.1
    `-- @jest/core@26.6.1
      `-- jest-config@26.6.1
        `-- babel-jest@26.6.1

[32;1m$ npm run build[0;m

cmds-ui-operations@0.1.2 build react-scripts build

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:

"babel-jest": "^24.9.0"

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

/builds/ielts-cmds/IELTS-CMDS-ui-grp/cmds-ui-operations/node_modules/babel-jest (version: 26.6.1)

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 "babel-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:

  1. 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.

  2. Check if /builds/ielts-cmds/IELTS-CMDS-ui-grp/cmds-ui-operations/node_modules/babel-jest is outside your project directory. For example, you might have accidentally installed something in your home folder.

  3. Try running npm ls babel-jest in your project folder. This will tell you which other package (apart from the expected react-scripts) installed babel-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.

For anyone coming across this in future - I ran into this same problem when installing Jest in the server folder containing a nested client created by CRA. My solution was to match the version of Jest that is installed by CRA in my server side package.json.

In my case, on the client side I was using: "react-scripts": "4.0.3"

Which has the following dependency: "jest": "26.6.0"

So in the server package.json I required the same version of jest. Deleted server node_modules & package-lock and did clean npm install.

Now both server & client are using the same version of jest (& nested deps).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM