package.json override dependencies peer dependencies
Asked Answered
L

2

8

When running npm i in one of my projects I get the follow error:

npm ERR! Found: [email protected]
npm ERR! node_modules/react
npm ERR!   react@"^17.0.2" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer react@"^16.13.1" from [email protected]
npm ERR! node_modules/react-qr-barcode-scanner
npm ERR!   react-qr-barcode-scanner@"*" 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.

I have read about the overrides property in package.json but this only seems to work for overriding "regular" dependencies.

I do also know that I can simply run npm i --legacy-peer-deps as the error suggests but I can't help but wonder:

Is there a way to override a dependencies peer dependencies without requiring --legacy-peer-deps?

Largent answered 17/5, 2022 at 8:19 Comment(8)
What exactly are you hoping to override? Is the react-qr-barcode-scanner package a direct dependency of your project or is it transitive (a dependency of a dependency)? That package appears to be abandoned. There's a bug report asking for React 17 support in which somebody has made a forkBeefeater
@LiuNate good luck getting anywhere with your bounty. This question needs clarification and OP hasn't touched it in over 5 yearsBeefeater
I saw this was asked only 3 months ago. I am having the same concern that my npm v8 does not override peerDeps and npm install never succeeds for those conflicting peerDeps deep in my deps.Onlybegotten
@Beefeater the question was asked only 3 months ago, its May 17, 2022. Not May 2017. Just to clarify, I have yet to find a proper answer to this as well. My current solution is using the --legacy-peer-deps flag, which is less than ideal.Pugliese
@Beefeater Basically, the react-qr-barcode-scanner package in this case works perfectly in React 17. The only thing preventing us from using it is the fact that it's package.json only lists React 16 as a peer dependency. Which fails npm's new peer dependency check. I wondered if there was a way to tell npm that that dependency has listed incorrect peer dependencies without explicitly having to run npm i with the --legacy-peer-deps flag and disabling the checks alltogether.Pugliese
@Luze "the question was asked only 3 months ago"... I'm an idiot 🤦, thanks for the correction. If you've got react-qr-barcode-scanner as a direct dependency, consider using the forked project with updated package.jsonBeefeater
@Luze see also this answerBeefeater
or just contribute back to that open source, what a WIN-WIN 🎉Onlybegotten
B
0

This is a known issue, seems like author dropped support for this package.

You can replace with forked one to solve this problem, created by @steima

https://www.npmjs.com/package/@steima/react-qr-barcode-scanner

Barbee answered 16/9, 2022 at 2:50 Comment(0)
B
-1

npm update ; npm i --force

secondly. your next option is clear package.json. and npm init. and try installing latest versions of all dependencies. and never upgrade until absolutely necessary.

Baronet answered 14/9, 2022 at 19:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.