Home > Software design >  Why ERR! ERESOLVE unable to resolve dependency tree is thrown and how to resolve it?
Why ERR! ERESOLVE unable to resolve dependency tree is thrown and how to resolve it?

Time:12-27

In my React Native application, I want to install React Native Firebase Auth module with this command:

npm install --save @react-native-firebase/auth

But I'm getting the following error:

ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: [email protected]
npm ERR! Found: @react-native-firebase/[email protected]
npm ERR! node_modules/@react-native-firebase/app
npm ERR!   @react-native-firebase/app@"^14.11.1" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer @react-native-firebase/app@"16.5.0" from @react-native-firebase/[email protected]
npm ERR! node_modules/@react-native-firebase/auth
npm ERR!   @react-native-firebase/auth@"*" 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.

My packaje.json file:

"react-native": "0.68.2",
"@react-native-firebase/app": "^14.11.1",
"@react-native-firebase/messaging": "^14.11.1",

Thanks in advance!

CodePudding user response:

Explanation

If you install @react-native-firebase/auth in a separate folder after an npm init -y, and open its folder by looking into node_modules, you would see in its package.json this:

"peerDependencies": {
  "@react-native-firebase/app": "16.5.0"
},

It means that it needs version 16.5.0 of @react-native-firebase/app in order to work, while you, in your package.json, have version 14.11.1; this is the problem.

But the thing is that @react-native-firebase/messaging version 14.11.1 needs the version 14.12.0 of @react-native-firebase/app, as it has in its package.json:

 "peerDependencies": {
   "@react-native-firebase/app": "14.12.0"
 },

Solution

The solution is to find versions that would make all of them agree. In your specific case, one way would be first to upgrade both of them to their latest versions:

npm i --save @react-native-firebase/messaging@latest @react-native-firebase/app@latest

And then, install @react-native-firebase/auth:

npm i --save @react-native-firebase/auth
  • Related