43

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"
  },

9 Answers 9

102

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.

1
  • 1
    Trying install another npm package and got similar errors. Installing with option --legacy-peer-deps solved the issues.
    – Caco
    Jun 14, 2021 at 17:23
16

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.

1
  • I tried to use the recommended version of node, still has the error
    – zEn feeLo
    Jul 14, 2022 at 3:07
14

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.

2
  • what is the pod file?
    – zEn feeLo
    Jul 14, 2022 at 3:09
  • 1
    @KamranAsgari pod file is in ios development where the packages are installed. Jan 12 at 18:00
4

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

4

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

2
  • Or you can use the official node.js downloads at https://nodejs.org/en/download/releases/. For me, 12.14.1 was too old, I had to use 12.22.5 for MacOS to be happy with it.
    – hlongmore
    Jul 18, 2022 at 17:45
  • Thanks FROM node:12.14.1-alpine it work Aug 1, 2022 at 11:53
2

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]

1

I faced the same issue, so id run this command npm config set legacy-peer-deps true

Then I simply created my react app using redux template by following

npx create-react-app app-name --template redux

worked for me!!

-1

Its a little bit late but you can resolve this with --force or --legacy-peer-deps options. Either should work as mentioned in the error reported by npm

-3

Try adding it with yarn. Worked for me

1
  • Thank you, worked for me after installing yarn via npm install -g yarn Oct 10, 2021 at 5:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.