8

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

npm ERR! Found: react@17.0.2
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 react-qr-barcode-scanner@1.0.6
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?

Luïs
  • 2,671
  • 1
  • 20
  • 33
  • What exactly are you hoping to override? Is the [react-qr-barcode-scanner](https://github.com/jamenamcinteer/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](https://github.com/jamenamcinteer/react-qr-barcode-scanner/issues/24) in which somebody has made [a fork](https://www.npmjs.com/package/@steima/react-qr-barcode-scanner) – Phil Sep 08 '22 at 07:34
  • 1
    @LiuNate good luck getting anywhere with your bounty. This question needs clarification and OP hasn't touched it in over 5 years – Phil Sep 08 '22 at 07:36
  • 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. – Liu Nate Sep 08 '22 at 10:43
  • 3
    @Phil 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. – Luïs Sep 08 '22 at 13:03
  • @Phil 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. – Luïs Sep 08 '22 at 13:09
  • @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](https://www.npmjs.com/package/@steima/react-qr-barcode-scanner) with updated `package.json` – Phil Sep 08 '22 at 23:41
  • @Luze see also [this answer](https://stackoverflow.com/a/73572077/283366) – Phil Sep 08 '22 at 23:47
  • or just contribute back to that open source, what a WIN-WIN – Liu Nate Sep 12 '22 at 00:40

2 Answers2

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

Hoàng Huy Khánh
  • 1,071
  • 8
  • 16
-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.

nikhil swami
  • 2,360
  • 5
  • 15