Home > Back-end >  NPM INSTALL failed on react-native project : "unable to resolve dependency tree for react & rea
NPM INSTALL failed on react-native project : "unable to resolve dependency tree for react & rea

Time:12-18

I'm going to start working on a react-native project with another developer, but i've worked on another project before this one and it ran on an android emulator without errors.

I cloned the project from https://github.com/ismail-benlaredj/ld-vetrinalive-reactnative and ran npm install which resulted in this error :

PS G:\Workspaces\React Native\ld-vetrinalive-reactnative> npm install
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: [email protected]
npm ERR! Found: [email protected]
npm ERR! node_modules/react
npm ERR!   react@"18.0.0" from the root project
npm ERR!   peer react@"*" from [email protected]
npm ERR!   node_modules/native-base
npm ERR!     native-base@"^3.4.25" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react@"^18.2.0" from [email protected]
npm ERR! node_modules/react-dom
npm ERR!   peer react-dom@"*" from [email protected]
npm ERR!   node_modules/native-base
npm ERR!     native-base@"^3.4.25" 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.
npm ERR!
npm ERR! See C:\Users\DEV-ABDOU\AppData\Local\npm-cache\eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\DEV-ABDOU\AppData\Local\npm-cache\_logs\2022-12-17T21_35_51_753Z-debug.log

and this is the eresolve-report.txt :

# npm resolution error report

2022-12-17T21:35:51.742Z

While resolving: [email protected]
Found: [email protected]
node_modules/react
  react@"18.0.0" from the root project
  peer react@"*" from [email protected]
  node_modules/native-base
    native-base@"^3.4.25" from the root project

Could not resolve dependency:
peer react@"^18.2.0" from [email protected]
node_modules/react-dom
  peer react-dom@"*" from [email protected]
  node_modules/native-base
    native-base@"^3.4.25" from the root project

Fix the upstream dependency conflict, or retry
this command with --force, or --legacy-peer-deps
to accept an incorrect (and potentially broken) dependency resolution.

Raw JSON explanation object:

{
  "code": "ERESOLVE",
  "current": {
    "name": "react",
    "version": "18.0.0",
    "whileInstalling": {
      "name": "nativetestapp",
      "version": "0.0.0",
      "path": "G:\\Workspaces\\React Native\\ld-vetrinalive-reactnative"
    },
    "location": "node_modules/react",
    "isWorkspace": false,
    "dependents": [
      {
        "type": "prod",
        "name": "react",
        "spec": "18.0.0",
        "from": {
          "location": "G:\\Workspaces\\React Native\\ld-vetrinalive-reactnative"
        }
      },
      {
        "type": "peer",
        "name": "react",
        "spec": "*",
        "from": {
          "name": "native-base",
          "version": "3.4.25",
          "whileInstalling": {
            "name": "nativetestapp",
            "version": "0.0.0",
            "path": "G:\\Workspaces\\React Native\\ld-vetrinalive-reactnative"
          },
          "location": "node_modules/native-base",
          "isWorkspace": false,
          "dependents": [
            {
              "type": "prod",
              "name": "native-base",
              "spec": "^3.4.25",
              "from": {
                "location": "G:\\Workspaces\\React Native\\ld-vetrinalive-reactnative"
              }
            }
          ]
        }
      }
    ]
  },
  "currentEdge": {
    "type": "prod",
    "name": "react",
    "spec": "18.0.0",
    "from": {
      "location": "G:\\Workspaces\\React Native\\ld-vetrinalive-reactnative"
    }
  },
  "edge": {
    "type": "peer",
    "name": "react",
    "spec": "^18.2.0",
    "error": "INVALID",
    "from": {
      "name": "react-dom",
      "version": "18.2.0",
      "whileInstalling": {
        "name": "nativetestapp",
        "version": "0.0.0",
        "path": "G:\\Workspaces\\React Native\\ld-vetrinalive-reactnative"
      },
      "location": "node_modules/react-dom",
      "isWorkspace": false,
      "dependents": [
        {
          "type": "peer",
          "name": "react-dom",
          "spec": "*",
          "from": {
            "name": "native-base",
            "version": "3.4.25",
            "whileInstalling": {
              "name": "nativetestapp",
              "version": "0.0.0",
              "path": "G:\\Workspaces\\React Native\\ld-vetrinalive-reactnative"
            },
            "location": "node_modules/native-base",
            "isWorkspace": false,
            "dependents": [
              {
                "type": "prod",
                "name": "native-base",
                "spec": "^3.4.25",
                "from": {
                  "location": "G:\\Workspaces\\React Native\\ld-vetrinalive-reactnative"
                }
              }
            ]
          }
        }
      ]
    }
  },
  "strictPeerDeps": false,
  "force": false
}

  • I dont know if i should include the lengthy npm log or not ( let me know ).

The problem :

  • i dont know how to interpret the error messages ( resolve the peer dependencies )
  • the console suggests to use the flags : --force, or --legacy-peer-deps at my own risk, i'm hesitant about doing that because it says
... to accept an incorrect (and potentially broken) dependency resolution.

and it's the reason i'm asking for help here.

Similar questions on SOF :

React Native app's npm install fails due to conflicting versions of react and react-dom

What i've tried so far :

Most answers i saw online suggested that i update my global react-native-cli but according to the docs here they ask you to uninstall it.

Also some answers pointed to some environment variables not being set properly, this isnt the case for me, since my other projects work fine.

CodePudding user response:

Try this.

npm cache verify
rm -rf node_modules
rm package-lock.json
npm i

This will clean the npm cache and rebuild the package-lock.json and node_modules

If it doesnt work, let me know and i will clone the repo and take a look.

  • Related