package.json override dependencies peer dependencies

1.9k Views Asked by At

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?

2

There are 2 best solutions below

0
On

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

0
On

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.