Matt
Matt

Reputation: 35271

npm install - ERESOLVE unable to resolve dependency tree

I am trying to npm install but getting this error.

npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! While resolving: [email protected]
npm ERR! Found: @angular/[email protected]
npm ERR! node_modules/@angular/cdk
npm ERR!   @angular/cdk@"9.2.4" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer @angular/cdk@"8.2.3" from @angular/[email protected]
npm ERR! node_modules/@angular/material
npm ERR!   @angular/material@"8.2.3" 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.

Upvotes: 11

Views: 46348

Answers (5)

Naman Chandak
Naman Chandak

Reputation: 19

This error may be created due to cache which has its own dependencies for the root user.

This will change to edit permissions for the npm cache folder.

sudo chown -R 501:20 "/Users/"username"/.npm"

Now remove cache

sudo npm cache clean --force

Upvotes: 0

Aniket Raj
Aniket Raj

Reputation: 2141

npm i package-name -f

If above command does not solve the error then use below both commands in terminal :

npm config set legacy-peer-deps true
npm cache clean --force

Upvotes: 5

Alireza Rezaei Mojaz
Alireza Rezaei Mojaz

Reputation: 61

you have dependency conflicts.ignore it and install npm packages.try this:

npm install YourPackage --force

or

npm install YourPackage --legacy-peer-deps

Upvotes: 2

Franklin Ukaegbu
Franklin Ukaegbu

Reputation: 87

try npm install --legacy-peer-deps . This worked for me. But first make sure you delete your package-lock.json and node_modules.

Upvotes: 8

Matt
Matt

Reputation: 35271

I updated node.js to the latest recommended LTS version which is currently version 14. This is what is causing the problem.

I tried using --force and --legacy-peer-deps, but this didn't work.

The solution is to downgrade the node version to 12.

Here is a copy/paste solution to fix. Copy all of this code and paste in the terminal at the root of your project. (Where your package.json file that you are trying to install is.)

rm package-lock.json
rm -rfv node_modules
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
nvm install 12
nvm use 12
npm i

What is happening here?

  1. Remove the package-lock.json file
  2. Remove the node_modules directory (-rfv = recursive, force, verbose)
  3. Install nvm (Node Version Manager)
  4. Configure nvm
  5. Load nvm
  6. Use nvm to install node v12
  7. Tell this project to use node v12
  8. Use npm to install the packages

Upvotes: 8

Related Questions