Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unable to resolve dependency tree error for creating new angular project

Tags:

npm

angular

web

so today I wanted to create a new Angular project using the command ng new <projectname> and I got this error:

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/jasmine-core
npm ERR!   dev jasmine-core@"~3.6.0" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer jasmine-core@">=3.7.1" from [email protected]
npm ERR! node_modules/karma-jasmine-html-reporter
npm ERR!   dev karma-jasmine-html-reporter@"^1.5.0" 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.

I literally tried everything, I updated npm, installed Angular cli again, download and installed node again, npm audit, and a lot of other things but nothing happened.

Also as you can see error told me to use the command with --force, I tried but nothing happened, and with --legacy-peer-deps, I get the error as unknown option.

What is bothering me the most is that everything was working completely right last night and I changed nothing at all but suddenly I'm getting this error today.

like image 808
Nima Soltan Avatar asked May 07 '21 11:05

Nima Soltan


People also ask

How to Solve Unable to resolve dependency tree?

The easiest way to fix the issue is to pass an additional parameter –legacy-peer-deps to npm install. The --legacy-peer-deps tells the npm to ignore the peer dependencies and continue the installation of the package.

What is latest version of angular CLI?

The Angular latest Official stable version is Angular v13. 2.5, which is released on 2nd March 2022.

How to resolve NPM err unable to resolve dependency tree conflict?

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.

What does “eresolve unable to resolve dependency tree error” mean?

When you try to install an Angular or React JS application you may get the error message “ERESOLVE unable to resolve dependency tree error” in your command prompt. The reason for the error message is because of a dependency conflict.

How to run angular project without npm packages installation?

Run the Angular project creation without automatic npm packages installation: Edit package.json and change this... Note: The version 1.5.0 here was used because it is the version that appears in the error message and we are tying to be more conservative here. Please adapt the version according to your specific necessity.

How do I force NPM to ignore all peer dependencies?

use “–legacy-peer-deps” with npm command which tells npm to ignore all peerDependecies use “–force” with npm which tells npm to fetch the resources from its repository even when you have a copy in the local machine.


Video Answer


7 Answers

Open the folder you create with ng new and open the package.json file. In devDependencies change the version of "jasmine-core" 3.6.0 to 3.8.0 and "karma-jasmine-html-reporter" from 1.7.0 to 1.6.0 and save it. Then go back to Terminal and go to your project and run npm install. Now it works and you can run ng serve.

Edit 2021

"jasmine-core": "~3.8.0",
"karma-jasmine-html-reporter": "^1.7.0"
like image 178
David Öztürk Avatar answered Oct 20 '22 10:10

David Öztürk


Mine is a temporary solution for angular-cli v11.2.12 based on @david-Öztürk answer and on this angular-cli github issue discussions and on its merged fix.

By executing the steps listed on @david-Öztürk answer I was still getting the same error. And also the fix is more conservative than the proposed solution. I hope it helps someone else:

Run the Angular project creation without automatic npm packages installation:

ng new --skip-install <project-name>

Enter project directory:

cd <project-name>

Edit package.json and change this...

"karma-jasmine-html-reporter": "^1.5.0",

...to this:

"karma-jasmine-html-reporter": "~1.5.0",

Manually install npm packages:

npm install

Note: The version 1.5.0 here was used because it is the version that appears in the error message and we are tying to be more conservative here. Please adapt the version according to your specific necessity. For newer projects the version 1.7.0 may be more suited but it can change with time. Read your specific error message in order to chose what better addresses your specific case.

like image 29
Iogui Avatar answered Oct 20 '22 10:10

Iogui


I had the same problem and I solved it with reinstalling nodeJs 14.16.1 but I had to change the version of npm manually with the command

npm install -g [email protected]

After of course, I tested the modifications by creating a project

ng new <MyProjet>
like image 15
Maxime Avatar answered Oct 20 '22 11:10

Maxime


If you are still facing this problem then try to make sure your package.json have all versions matching other supporting library versions. The jasmine-core had to be greater than 3.8 with karma-jasmine-html-report 1.7+

here is how my devDependecies looked inside package.json

"devDependencies": {
    "@angular-devkit/build-angular": "~12.0.0",
    "@angular/cli": "~12.0.0",
    "@angular/compiler-cli": "~12.0.0",
    "@types/jasmine": "~3.6.0",
    "@types/node": "^12.11.1",
    "jasmine-core": "~3.8.0",
    "karma": "~6.3.0",
    "karma-chrome-launcher": "~3.1.0",
    "karma-coverage": "~2.0.3",
    "karma-jasmine": "~4.0.0",
    "karma-jasmine-html-reporter": "^1.7.0",
    "typescript": "~4.2.3"
  }
like image 9
Prashant Rajput Avatar answered Oct 20 '22 10:10

Prashant Rajput


Looks like the issue with latest NPM 7.12.0 and the latest Node 16.1.0(Current Version)

In my case I followed the below steps -

  1. Uninstall Node
  2. Re-Install the Latest Node (LTS: 14.16.1)
    • Which will install the latest NPM : 6.14.12
  3. Run the ng new my-app
like image 7
MBB Avatar answered Oct 20 '22 12:10

MBB


install node, if you do not have it or update to the newest version: https://nodejs.org/en/download/package-manager/

update your npm: npm install npm@latest -g

optional : npm i update-node

This will update angular to its newest version: npm install -g @angular/cli Create a new angular project: ng new projectName Change directory the projectName: cd projectName Serve the project ng s

like image 5
Caesarius Avatar answered Oct 20 '22 10:10

Caesarius


What it worked for me was manually update package.json to look like this

"jasmine-core": "~3.8.0",
"karma-jasmine-html-reporter": "^1.7.0"

and then I tried

npm install

but didn't work either so I tried

npm install --legacy-peer-deps

and then everything worked again I was able to do npm start as usual

like image 5
Jeyson Mg Avatar answered Oct 20 '22 12:10

Jeyson Mg