When I run `ng new`, npm has a dependency problem

Viewed 10685

i ran ng new in terminal. I ended up getting an npm error

  1. new folder
  2. run ng new in new folder
  3. set the name and accept defaults (and use SCSS)
  4. watch it create files and error at the end
⠸ Installing packages (npm)...npm ERR! code ERESOLVE
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.7.1
npm ERR! node_modules/jasmine-core
npm ERR!   dev jasmine-core@"~3.7.0" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer jasmine-core@">=3.8" from karma-jasmine-html-reporter@1.7.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.
npm ERR! 
npm ERR! See /Users/user/.npm/eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/user/.npm/_logs/2021-07-11T18_12_50_796Z-debug.log
✖ Package install failed, see above.
The Schematic workflow failed. See above.
2 Answers

I had this same issue with a fresh project, etc.

In the generated package.json you should see a line that says "jasmine-core": "~3.7.0" but it seems that other dependencies (I believe karma based on the error output here) require jasmine-core at 3.8.0 or higher. Simply edit the line that says "jasmine-core": "~3.7.0", to be "jasmine-core": "~3.8.0", and then manually run npm install and it should succeed.

You should then be able to run ng serve --open from the same directory and have it run just fine.

I changed "jasmine-core": "~3.7.0", to "jasmine-core": "~3.8.0" in package.json.template, I can create projects with no issues now. The location may vary, mine is: /usr/local/lib/node_modules/@angular/cli/node_modules/@schematics/angular/workspace/files/package.json.template

This will fix the problem in new projects

Related