node.jsreactjsnpmdependency-tree

ERESOLVE unable to resolve dependency tree.While installing npm package react-alert


PS C:\Users\OneDrive\Desktop\MERN Project\frontend> npm i react-alert npm ERR! code ERESOLVE npm ERR! ERESOLVE unable to resolve dependency tree npm ERR! npm ERR! While resolving: frontend@0.1.0 npm ERR! Found: react@18.2.0 npm ERR! node_modules/react npm ERR! react@"^18.2.0" from the root project npm ERR! npm ERR! Could not resolve dependency: npm ERR! peer react@"^16.8.1 || ^17" from react-alert@7.0.3 npm ERR! node_modules/react-alert npm ERR! react-alert@"*" 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\lodhi\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\lodhi\AppData\Local\npm-cache_logs\2022-10-05T08_57_49_898Z-debug-0.log


Solution

  • This happens when the package you're installing has a different version compared to your local package. There are 2 ways to solve this issue.

    The first way ( easy way )

    Just do npm install packagename --legacy-peer-deps or npm install packagename --force

    The second way ( hard way )

    If the above doesnt work, then you need to figure out which packages are causing conflict and add this line into your package.json

    #for npm users
    overrides: {
    packagename: "add local version here"
    }
    
    
    #for yarn users
    resolutions: {
    packagename: "add local version here"
    }