unable to resolve dependency tree error for creating new angular project

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.


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"

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

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>

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"
  }