177

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: project-name@0.0.0
npm ERR! Found: jasmine-core@3.6.0
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 karma-jasmine-html-reporter@1.6.0
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.

General Grievance
  • 4,555
  • 31
  • 31
  • 45
Nima Soltan
  • 1,773
  • 2
  • 6
  • 6

16 Answers16

341

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"
Community
  • 1
  • 1
David Öztürk
  • 3,434
  • 1
  • 4
  • 7
  • Versions can be different based on what version of Angular/CLI or NPM is installed. I had to change the versions again after changing NPM version. – Jay Bhiyani Jul 12 '21 at 10:47
  • 2
    I've been having this problem for a while, but I was already at jasmine-core 3.7.1. Instead, I had to use `npm i --legacy-peer-deps` to get anywhere. Today I found jasmine-core 3.8.0 available, and that finally fixes the problem for me. – kshetline Jul 25 '21 at 00:39
  • Yes. Worked for me as well. – Subhashi Aug 02 '21 at 05:19
  • 7
    Any idea if this is something that can be changed/fixed on my end to prevent this, or is it a cli bug? Pretty bad when you have to google workarounds just to create an Angular hello world project. – reads0520 Aug 23 '21 at 19:06
  • 1
    Still working in 2022 – afe Jan 12 '22 at 10:56
  • 3
    It works form me, thanks, but I think that errors like that are not accepatable :) – Hazem HASAN Jan 19 '22 at 16:50
  • 1
    This seems to have worked for me, too. But still, I literally just created a new project and didn't change anything about it, so why did I get this error to begin with?! – Chris Apr 12 '22 at 08:03
  • 4
    It is really a shame to get an error, you are no responsible of, at the start of a project ! And really horrible for beginners ! – moueza May 13 '22 at 11:27
37

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.

Iogui
  • 1,526
  • 1
  • 17
  • 28
  • adding the "~" to 1.5.0 worked for me. I am updated to angular version 12.2.4. I had to throw out my package-lock.json first. a silly workaround but what you gonna do. thanks Iogui! – Ian Poston Framer Sep 03 '21 at 21:04
  • 1
    @IanPostonFramer I belive that if you run `npm install` after manually changing your `package.json` file it updates your `package-lock.json` for you. Anyway, the first step with the `--skip-install` flag should not generate a package-lock.json avoiding this problem. – Iogui Sep 04 '21 at 02:54
  • https://stackoverflow.com/a/25861938/981766 – Sahil Singh Jun 15 '23 at 08:24
20

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 npm@6.14.12

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

ng new <MyProjet>
Maxime GH
  • 427
  • 4
  • 7
9

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
MBB
  • 1,635
  • 3
  • 9
  • 19
  • 3
    thanks! works like a charm. I use nvm, so my steps were: "nvm install --lts" then reinstall angular "npm install -g @angular/cli" and it worked perfectly – Ryan Loggerythm May 11 '21 at 20:16
  • 1
    This solution is perfect. Just remember to remove the npm and node folders from `%userprofile%/AppData/Roaming` after running the uninstall step. This way you can be sure that you've fully deleted node & npm. – Ali Khakpouri Jul 14 '21 at 04:00
9

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"
  }
Prashant Rajput
  • 141
  • 1
  • 3
7

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

Jeyson Mg
  • 150
  • 1
  • 6
5

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

Caesarius
  • 115
  • 5
5

You can update angular cli globally: npm update @angular/cli -g

4

They have released Karma Jasmine html reporter few hours ago. This maybe what is breaking the code. The update is most likely the cause.

You should change the package.json and get the older version of the Karma Jasmine older version

MBB
  • 1,635
  • 3
  • 9
  • 19
NoviceDeveloper
  • 1,270
  • 3
  • 15
  • 41
1

I solved this issue by using this command inside my project directory:

  1. npm install --save-dev @angular-devkit/build-angular --force
  2. npm audit fix --force

then I ran my project using "ng serve"

1

Edit the package.json in your project folder.

"jasmine-core": "~3.7.0" to "jasmine-core": "~3.8.0", "karma-jasmine-html-reporter": "^1.5.0" to "karma-jasmine-html-reporter": "^1.6.0"

After run npm install in your project folder.

0

Error Details after doing ng new my-app

npm ERR! Could not resolve dependency:

npm ERR! peer jasmine-core@">=3.7.1" from karma-jasmine-html-reporter@1.6.0

Fix Details

  1. sudo npm install -g npm@7.13.0 => updated npm from 7.10.0 to 7.13.0
  2. Only changed "jasmine-core" from 3.6.0 to 3.7.1 i.e "jasmine-core": "~3.7.1", in package.json
  3. npm install

After this found no issues and I was able to do ng build and ng serve.

Other settings I left as it was : "@types/jasmine": "~3.6.0", "jasmine-spec-reporter": "~5.0.0",

Manish Kumar
  • 191
  • 1
  • 9
0

Does not help update npm nor node.js. Strange error, strange error mesages. Does help to update package.json - change version of something 'jasmine' - "jasmine-core": "~3.8.0". I don't know what is it for, but it make problems.

bmi
  • 652
  • 2
  • 10
  • 17
0

Just do the following in the package.json

"jasmine-core": "~3.8.0",

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

then do npm install

Imal Hasaranga Perera
  • 9,683
  • 3
  • 51
  • 41
0

I encountered this issue today, after updating npm to latest - currently 8.5.3. THen I simply run ng new <my-new-project> from command-line, adding Angular Route I answered y, and selected SCSS. ng did his thing and I got the error, only different versions:

Angular 12

  • No jasmine-core - In the error states "jasmine-code@3.7.1" and I need "jasmine-code@>=3.8")
  • No karma-jasmine-html-reporter (error states "@^1.5.0" and I need "@1.7.0")
  • Checked node_modules and packages.json- no mention, nor trace, of those.

After reading this issue and answers. I decided to update my Angular to the latest and run ng -g i angular-cli@latest and I received an error that the file ng.cmd already exists in folder {Windows-users-username-folder}\AppData\Roaming\npm\ng.cmd - I deleted the file. The 2nd time I run the update of Angular I received the same error on file ng. (deleted it) and the 3rd time the error was on ng.ps1 (deleted it three). Then update of Angular was successful. Then I run ng new <my-new-project> and it was successful as well.

By the way, in my new project's packages.json I see:

"devDependencies": {
    "@angular/compiler-cli": "^2.3.1", 
    "@types/jasmine": "2.5.38", 
    "@types/node": "^6.0.42",
    "angular-cli": "1.0.0-beta.28.3",
    "codelyzer": "~2.0.0-beta.1",
    "jasmine-core": "2.5.2",
    "jasmine-spec-reporter": "2.5.0",
    "karma": "1.2.0",
    "karma-chrome-launcher": "^2.0.0",
    "karma-cli": "^1.0.1",
    "karma-jasmine": "^1.0.2",
    "karma-remap-istanbul": "^0.2.1",
    "protractor": "~4.0.13","ts-node": "1.2.1", "tslint": "^4.3.0", 
    "typescript": "~2.0.3"
}

Nothing even remotely similar to what was stated in the error.

Binyamin Regev
  • 914
  • 5
  • 19
  • 31
-2

If you're still experiencing this after trying some/all of the above options, Just downgrade npm version from 7 to 6: npm install -g npm@6

CodeTzu
  • 45
  • 5