14
"@popperjs/core": "^2.6.0",
"@testing-/jest-dom": "^5.11.9",
"@testing-/react": "^11.2.3",
"@testing-/user-event": "^12.6.2",
"bootstrap": "^4.6.0",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-scripts": "4.0.1",
"react-transition-group": "^4.4.1",

versions of dependencies I have in package.json file.

G:\Projects\React\confusion> npm install --save reactstrap

npm WARN ERESOLVE overriding peer dependency
npm WARN Found: [email protected]
npm WARN node_modules/react
npm WARN peer react@"" from @testing-/[email protected]
npm WARN node_modules/@testing-/react
npm WARN @testing-/react@"^11.2.3" from the root project
npm WARN 3 more (react-dom, the root project, reactstrap)
npm WARN
npm WARN Could not resolve dependency:
npm WARN peer react@"0.14.x || ^15.0.0 || ^16.0.0" from [email protected]
npm WARN node_modules/react-popper
npm WARN react-popper@"^1.3.6" from [email protected]
npm WARN node_modules/reactstrap
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! npm ERR! Found: [email protected]
npm ERR! node_modules/react
npm ERR! peer react@"
" from @testing-/[email protected]
npm ERR! node_modules/@testing-/react
npm ERR! @testing-/react@"^11.2.3" from the root project
npm ERR! peer react@"17.0.1" from [email protected]
npm ERR! node_modules/react-dom
npm ERR! peer react-dom@"" from @testing-/[email protected]
npm ERR! node_modules/@testing-/react
npm ERR! @testing-/react@"^11.2.3" from the root project
npm ERR! react-dom@"^17.0.1" from the root project
npm ERR! 1 more (reactstrap)
npm ERR! 2 more (the root project, reactstrap)
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react@"^0.14.0 || ^15.0.0 || ^16.0.0" from [email protected]
npm ERR! node_modules/react-popper/node_modules/create-react-context
npm ERR! create-react-context@"^0.3.0" from [email protected]
npm ERR! node_modules/react-popper
npm ERR! node_modules/reactstrap
npm ERR! reactstrap@"
" 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.

8 Answers 8

24

This is because of a change in npm version 7. See the breaking changes section here. You can fix it by using the flag the error tells you to use at the bottom: npm i reactstrap --legacy-peer-deps. If one of your other dependencies already has reactstrap as a peer dependency, you might not need to install it at all (you can check with npm ls reactstrap), due to the change in v7.

Sign up to request clarification or add additional context in comments.

Comments

17

Try something like this in your package.json

  "engines": {
    "npm": ">=8.7.0"
  },
  "overrides": {
    "react": "$react"
  }

This will force react to be the version defined in your "dependencies" for all dependencies (& deps of deps). You need "recent" npm as it was buggy in some version (I had 8.3.0 and overrides wasn't working). 8.7.0 seems ok !

See https://docs.npmjs.com/cli/v8/configuring-npm/package-json#overrides

5 Comments

npm ERR! Unable to resolve reference $react
Double check your NPM version.
Using latest version of npm 8.19.1 and still getting npm ERR! Unable to resolve reference $react i have double checked that react exists on dependencies but still the same error .
I am not sure why, but in some project I explicitly mentioned the version instead of using ${package}....
This is the way: you say what you want to override. Thank you.
11

There is 2 ways to fix this.

Method 1:

You can specify --legacy-peer-deps flag when you install a new package.

# For NPM
npm install package_name --legacy-peer-deps

#For Yarn
yarn add package_name --legacy-peer-deps

Method 2:

If you dont want to specify the --legacy-peer-deps flag everytime when you install a new package for the project.

You can simply create a file at the root directory of your project. The file name will be .npmrc (For NPM) or .yarnrc (For Yarn). Update the file with this:

For .npmrc:

legacy-peer-deps=true

For .yarnrc:

npmClientArgs: "--legacy-peer-deps"

Hope it helps you :)

1 Comment

Method is worked for me.
2

to install write this command in your terminal

step 1) if you're using npm

npm install your_package_name --legacy-peer-deps

step 2) if you're using yarn

yarn add your_package_name --legacy-peer-deps

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
0

Delete node modules, then npm i reactstrap --legacy-peer-deps then npm install --force solved it for me

Comments

0

To install any dependency forcefully run the below command: npm i --force this command install the package forcefully without giving any error.

Comments

0

I have been fighting exactly this problem with a different package, "video-react". So the problem is the same, video react supports only an older version of React.

The --force and --legacy-peer-deps arguments to NPM will work but are simply not good enough when deploying to cloud. So for example the GitHub Actions deployment script to Azure does not allow extra arguments to the "npm install" command. Of course, you could modify the script, but why swim upstream?

So here is the package.json magic that solved my issue and will also solve the issue for the OP....

  "overrides": {
    "react": "$react",
    "react-dom": "$react-dom"
  }

Note that both "react" and "react-dom" have to be direct dependencies before the variables "$react" and "$react-dom" are defined. In my case "react" was missing (so pulled in by something else) and so $react was not defined. Fixed this by simply adding the react package to the direct dependencies.

Comments

-7

To resolve REACT_SPRING installation issue try

npm install  --force

then

npm audit fix --force

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.