164
votes

When trying to install the npm packages using npm i command I am getting the following exception:

enter image description here

I have tried reinstalling the node js package and setting proxy to off using:

set HTTP_PROXY=
set HTTPS_PROXY=

The issue is still there. What I am doing wrong?

Update:

When I run the following command:

npm install --legacy-peer-deps

The following error is displayed: enter image description here

29
Show your package.json - it looks like you've upgraded @angular/core, but did not upgrade @angular/http? - Adam
my @angular/core version is 9.1.4, so shall i update @angular/http? - Pearl
Please share your package.json file. The problem seems to be in your dependencies - Owen Kelvin
Can you try to delete package-lock.json and node_modules and try to run npm update? Let me know if it work. - Fmerco
is this still happening? Can you share the package.json file? - Supun Praneeth

29 Answers

231
votes

This is not related to http proxy.

You have dependency conflict (incorrect and potentially broken dependency) as it says, So try to to run the command with --force, or --legacy-peer-deps. If it doesn't take effect, the temporary solution is using prior versions of the node (Downgrading node version) as it causes to happen such this kind of errors sometimes.

Update based on OP's Update:

As you see, it fires the following error :

No matching version found for @angular/http@^9.1.4.

Take a look at angular/http page. Note that the latest version for that deprecated package is 7.2.16 while you request an upper version (e.g ^9.1.4)! So, try to check the project dependencies and follow the raised errors in order to solve the problem.

102
votes

Try this command-

npm install --save --legacy-peer-deps
43
votes

In addition to using the --legacy-peer-deps command line option, this can also be set more permanently as a config option:

npm config set legacy-peer-deps true
37
votes

When using npm 7, I have experienced this when working with a node_modules/package-lock.json generated with npm 6. Usually using --legacy-peer-deps makes it work.

When that doesn't work, an option is to downgrade to npm 6. Downgrading Node.js is not necessary (but not harmful either). The relevant dependency management code is in npm. Downgrading Node.js will often work coincidentally because doing so will often downgrade npm as well.

Another option that is less disruptive than downgrading npm is using npx to use the previous version of npm for just the install command: npx -p npm@6 npm install

And when all else fails, it's often worth a shot to remove the node_modules directory and package-lock.json, and then run npm install again. That regenerates node_modules and package-lock.json.

28
votes

This happens for some packages after updating to npm 7.

Paramter --legacy-peer-deps can help:

npm i --legacy-peer-deps

Described here legacy-peer-deps

Causes npm to completely ignore peerDependencies when building a package tree, as in npm versions 3 through 6.

If a package cannot be installed because of overly strict peerDependencies that collide, it provides a way to move forward resolving the situation.
...

You can set this option to true by default (not recommended by npm):

npm config set legacy-peer-deps true

Or just wait until these packages get up to date.

9
votes

Try removing the node modules and package-lock.json file and run command npm install or Try npm cache clean --force

4
votes

Hope my post can help you, first I tried

npm install

it gave me error unable to resolve dependency tree and base on the help information from this command

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 tried this command

npm install --legacy-peer-deps

And it solved my problem

4
votes

The fastest solution: npm install --legacy-peer-deps

Explains:

In npm versions 3 through 6, peerDependencies were not automatically installed, and would raise a warning if an invalid version of the peer dependency was found in the tree. As of npm v7, peerDependencies are installed by default.

npm docs: peerDependencies

Your dependency contains some peerDependencies, that conflict with the root project's dependency.

As it described in the npm ERR log.

3
votes

The problem seems to be that gf-kautomata-pipeline-ui is using Angular 9, while @angular/http requires Angular 7. (@angular/http was deprecated and eventually removed, and all its functionality was moved into @angular/common instead.)

See: https://www.npmjs.com/package/@angular/http

If you're running Angular 9, then

  1. delete @angular/http from your package.json (You don't need it in Angular 9)

  2. Make sure you have @angular/common in your package.json.

  3. Run npm i.

If you're running Angular 7, then open up your package.json and check to make sure all of your Angular packages are no higher than ^7.0.0. You may also need remove gf-kautomata-pipeline-ui, or contact the author of gf-kautomata-pipeline-ui and find out if the library is compatible with Angular 7.

2
votes

in my case, I started getting the error (below) after upgrading npm from version 6 to 7.

npm ERR! code ERESOLVE npm ERR! ERESOLVE unable to resolve dependency tree

...

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

In my case compiling with either --legacy-peer-deps or --force flags resulted in a useless bundle.

So I tried deleting the node_modules, package-lock.json, and bundle using yarn install. This generated a yarn.lock file and created package-lock.json that worked fine in subsequent npm runs.

p.s. I am using the temporal workaround until npm 7 works fine with my project: after that, I will delete yarn.lock, package-lock.json and node_modules, and recompile with npm

rm -rf node_modules
rm package-lock.json 
yarn install 
# generates a yarn.lock file and a new package-lock.json

# continue with npm 
npm start
2
votes

First to understand the problem. Here is what I have as error:

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/common
npm ERR!   @angular/common@"11.0.3" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer @angular/common@"^9.1.0 || ^10.0.0" from @agm/[email protected]
npm ERR! node_modules/@agm/core
npm ERR!   @agm/core@"3.0.0-beta.0" from the root project

First you should start to read the problem from the bottom to the top. Here @agm/[email protected] requires angular common 9.1.0 or 10.0.0. And the top message says that the angular common found is actually 11.0.3.

(If you want to understand dependencies little bit better, here is very simple site https://npm.github.io/how-npm-works-docs/npm3/how-npm3-works.html)

dependencies — these are the essential dependencies that you rely on and call in your project’s code
devDependencies — these are your development dependencies, for example, a prettier library for formatting code
peerDependencies — if you set a peer dependency in your package.json, you are telling the person who installs your package that they need that dependency with the specified version
optionalDependencies — these dependencies are optional and failing to install them will not break the installation process
bundledDependencies — it’s an array of packages that will come bundled with your package. This is useful when some 3rd party library is not on NPM, or you want to include some of your projects as modules

So what should be the solution then? The problem is about peer dependencies. The solution is to downgrade angular common OR the solution is to use legacy dependencies logic for installing packages using --legacy-peer-deps. So what --legacy-peer-deps does is not to try to install the peerDependencies automatically. Is this going to work for you? Probably yes. But you should put specific instruction how to do that, or to make the use of --legacy-peer-deps automatic for future installation of the project packages with this code from one of the answers above:

npm config set legacy-peer-deps true

In my case I installed the package and I tried to run ng serve, but because --legacy-peer-deps was used, there were dependency packages which were not installed. I had to install those manually (because I did not set the config from the code above). At the end installing about 5 packages manually, all with --legacy-peer-deps, I ended to a package that could not be installed and I did not try to continue, because my project was throwing warnings like crazy and there were a lot of packages for audit too. So my decision was not to use this package and to find alternative.

Other solutions that I read about along the way:

  • downgrade node to v14, this will downgrade npm. Might not be v14, but this was the version that was most widely downgraded to.
  • Some people use yarn to force package installation - personally I don't understand how this works, because I haven't used yarn.
  • downgrading angular and the global angular cli version to version that will satisfy the requirement. In my case it is angular/common, and in the question it's angular/core, but both require downgrading the whole angular right(not sure about this here).
  • the package you install might have higher version that doesn't require downgrading angular. You might try to use the https://updatepackagejson.com/ to upgrade your packages to the latest, but this is in case your project is quite new.
1
votes

In my case I was having trouble with @babel/core dependency, but didn't want to use --force because I was not sure about the consequences, so I went to https://www.npmjs.com/, looked for the package and replaced my old version with the newest one. That did the work

0
votes

I just Update my node and it works for me :

$ node -v

 V xxxx
    
$ sudo npm install -g n

(Use this command to install the stable node release.)

$ sudo n stable

Hope it workd for you too !!!

0
votes

Here is the solution.

got to the project directory

sudo rm ./package-lock.json
sudo npm install --force
0
votes
  1. If you have node_modules folder and package-lock.json file in your root directory then remove those:
rm -r node_modules
rm package-lock.json
  1. Then run commands:
npm install --save --legacy-peer-deps
npm audit fix --force
  1. Create .env file in the root directory and paste below code:
SKIP_PREFLIGHT_CHECK=true
  1. Now, start your project:
npm start
0
votes

none of the answers above helped me. for me updating npm to the latest version(to 7.11.1 from 7.8) using npm i -g npm fixed the issue for me.

0
votes

Resetting package-lock.json works good for me all the time:

git checkout -- package-lock.json

Details: Been experiencing this a lot when updating all packages of the legacy project - I highly don't recommend using npm audit fix nor npm i --force. Deleting the package-lock.json didn't work for me all the time as well. Rollback to the working version of package.json + package-lock.json and add packages turned out to be the safest and fastest variant for me.

0
votes

I solved this with to lower the version of Node from last version to LTS version

0
votes

Just in case, I did have similar behavior, when I tried either npm upgrade my current Angular 11.x based boilerplate from previous ng new or create new ng new abc based on Angular 12.x. I simply forgot to upgrade Angular CLI. So this npm install -g @angular/cli@latest solved my errors during ng new abc.

0
votes

For those who are getting errors while installing Bootstrap Paginator or table next

npm install react-bootstrap-table2-paginator --save

or

npm install react-bootstrap-table-next --save

Solution: Add --legacy-peer-deps after the command like

  • npm install react-bootstrap-table2-paginator --save --legacy-peer-deps
  • npm install react-bootstrap-table-next --save --legacy-peer-deps
0
votes

I have faced this issue many time at last I found solution

         npm install react-native-paper  --legacy-peer-deps
0
votes

Even after uninstall/install NPM and CLI if still does not work then make sure you are inside the project folder. For example, you have created a root folder "myapplication". Now, you are running CLI command to create a brand new application under myapplication folder. After running command, you would get error like "ERESOLVE unable to resolve dependency tree". So, instead of running command on myapplication folder, go to new application folder inside myapplication folder and run/execute angular application. It would work fine.

0
votes

Problem is related to dependency conflict or broken dependency. You can procced by accepting the incorrection of dependency by forcing install.

Solution: Using command with --force.

Your command will be like npm install --force @your-npm-package.

Note: You can use yarn to install dependency if its available in to install with yarn package manager.

-1
votes
npm audit fix --force

Worked for me

-1
votes

Just Do Simple thing:

npm install --save --legacy-peer-deps
-2
votes

Finally found solution

  • install nvm
  • use nvm to install node
  • enter cmd to use lts version
  • after that my installation worked, it should be working for you too.
-2
votes

1.Add dependency in package.json 2. do npm install

still seeing the error?

  1. npm install --force
-2
votes

I had the same issue

npm install --legacy-peer-deps 

This works for mine too. But I have a more simple answer. Just change the version number of in the package.json that is required. Then use

npm i

This will solve your problem (Generate new project as usual, without any potentially broken dependency issue.)

-2
votes

Start with npm i --legacy-peer-deps flag first then use the --force flag next.