Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conflict between react script and jest version 24.7.1

After creating a react app with 'create-react-app' things have been successful till now. I have made a working react project. But now that I'm looking to implement unit testing with jest.

Using npm to install: 'npm install --save-dev jest' Then running: npm ls jest I notice that the react-script is looking for a jest version that is significantly older.

package.json:

"dependencies": {
"react": "^16.8.1",
"react-dom": "^16.8.1",
"react-redux": "^6.0.0",
"react-scripts": "2.1.5",
"redux": "^4.0.1"
},

"devDependencies": {
"jest": "^24.7.1"
},

"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "jest",
"eject": "react-scripts eject"
}

npm ls jest result:

+-- [email protected]
`-- [email protected]
  `-- [email protected]

npm start error:

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:

C:\Users\userName\sample js codes\redux\songs\node_modules\jest (version: 
24.7.1)

Is there a solution to solve this dependency version issue?

like image 308
kevin man Avatar asked Apr 11 '19 10:04

kevin man


People also ask

What version of Jest is required to install react-scripts?

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: C:\Users\userName\sample js codesedux\songs ode_modules\jest (version: 24.7.1)

Is react-test-renderer ready for jest testing?

It is ready to use and ships with Jest! You will only need to add react-test-renderer for rendering snapshots. If you have an existing application you'll need to install a few packages to make everything work well together. We are using the babel-jest package and the react babel preset to transform our code inside of the test environment.

Are there any version conflicts between yarn and react-scripts?

I would expect there to be no version conflicts in official packages which are part of the same official project and that running yarn run start would exit cleanly. Running yarn run start which runs react-scripts start outputs the following error:

Why can't I start react-scripts from create react app?

$ react-scripts start 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.7.1" Don't try to install it manually: your package manager does it automatically.


1 Answers

Create-react-app comes with Jest built-in, there is no need to install it additionally.

You have a version conflict now because you installed it additionally. To fix it, revert your changes to package.json.

like image 141
Patrick Hund Avatar answered Oct 19 '22 10:10

Patrick Hund