Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error when trying to install react-redux dependency

I am getting an error trying to install the react-redux package onto my create-react-app application. I have tried deleting and reinstalling my node_modules folder as well as installing it with admin permissions and I am still receiving the same error

➜  frontend git:(main) ✗ npm i react-redux
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree

Here is the remaining output from the console

npm ERR! 
npm ERR! While resolving: [email protected]
npm ERR! Found: [email protected]
npm ERR! node_modules/react
npm ERR!   react@"^17.0.1" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer react@"^16.8.3" from [email protected]
npm ERR! node_modules/react-redux
npm ERR!   react-redux@"*" from the root project
npm ERR! 
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.

Here is the list of current dependencies in my package.json

 "dependencies": {
    "@testing-library/jest-dom": "^4.2.4",
    "@testing-library/react": "^9.5.0",
    "@testing-library/user-event": "^7.2.1",
    "axios": "^0.21.0",
    "react": "^17.0.1",
    "react-bootstrap": "^1.4.0",
    "react-dom": "^17.0.1",
    "react-router-bootstrap": "^0.25.0",
    "react-router-dom": "^5.2.0",
    "react-scripts": "3.4.4",
    "redux": "^4.0.5",
    "redux-devtools-extension": "^2.13.8",
    "redux-thunk": "^2.3.0",
    "tachyons": "^4.12.0"
  },
like image 371
Moose Hamid Avatar asked Oct 25 '20 23:10

Moose Hamid


People also ask

How do you resolve peer dependencies?

Solution 1: Ignore the peerDependencies The easiest way to fix the issue is to pass an additional parameter –legacy-peer-deps to npm install. The --legacy-peer-deps tells the npm to ignore the peer dependencies and continue the installation of the package.

How install React JS npm?

To install the full React toolchain on WSL, we recommend using create-react-app: Open a terminal(Windows Command Prompt or PowerShell). Create a new project folder: mkdir ReactProjects and enter that directory: cd ReactProjects . npx is the package runner used by npm to execute packages in place of a global install.


Video Answer


6 Answers

It looks like you are using the latest npm version (v7). As mention in the logs, try with npm install --legacy-peer-deps


The last time npm Blog mentioned the --legacy-peer-deps flag was while their beta version of npm v7 got public. To read more about the flag go here.

like image 186
Alexandre Avatar answered Oct 18 '22 17:10

Alexandre


Try installing recommended nodejs version(screen shot below). Which should fix this issue.

enter image description here

Here is a recreation of this error and its solution (screenshots below):

Problem:

Nodejs : Latest features:

enter image description here

Solution:

Nodejs : Recommended for most users:

enter image description here

Installing the Recommended version of node js fixed this issue instantly allowing installation of relevant dependancies.

Incase you are facing this issue with a react-native dependency then once you have installed the recommended version be sure to update your pod file.

like image 27
Ali Shirazee Avatar answered Oct 18 '22 19:10

Ali Shirazee


Two ways:

  1. npm install <package-name> --legacy-peer-deps
  2. install Recommended node version for most users

The better way is to install the recommended version of node to work for all packages.

like image 14
Alireza Piran Avatar answered Oct 18 '22 17:10

Alireza Piran


Try using Node.js latest "Recommended For Most Users" Version . it worked for me

like image 4
Masoud Mohajeri Avatar answered Oct 18 '22 18:10

Masoud Mohajeri


I had this issue and nothing seemed to work. I fixed it by downgrading node to version 12.14.1 Uninstall the current node version and install 12.14.1 from this link

like image 3
Owais Tahir Avatar answered Oct 18 '22 19:10

Owais Tahir


Tried for Mac, it worked.. follow the steps for upgrading to the latest LTS

  1. Before updating the Node.js release, check which version you are currently using with: node -v

  2. Next, clear npm cache with the command: npm cache clean -f

  3. Install n globally: npm install -g n

  4. Now that you have n installed, you can use the module to install the latest stable release of Node.js: sudo n stable

Alternatively, you can install the Node.js release with the latest features:

sudo n latest

Or, install a specific version number with: n [version.number]

like image 2
rsb Avatar answered Oct 18 '22 19:10

rsb