Why ng new newApp producing unable to resolve dependency tree error

Viewed 6292

I am trying to create a new angular app using the command ng new app-name.. But after running the command, it is showing the following in the command line.

Installing packages (npm)...npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! While resolving: angular-module@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.
npm ERR! 
npm ERR! See /home/vazha/.npm/eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/vazha/.npm/_logs/2021-05-07T05_12_55_121Z-debug.log
āœ– Package install failed, see above.
The Schematic workflow failed. See above.

How can we fix this issue?

4 Answers

This error is caused by an npm 7 issue. The Angular team recommends to use npm 6 for now.

Run npm install -g npm@6 to ensure that you are using that version.

An alternative can be to run ng new with the --skipInstall flag, and then install the dependencies with npm install --legacy-peer-deps.

First create the project as usual:

ng new <project>

Then go to the project directory and change version of jasmine-core in package.json to "^3.7.1". Then start install again:

npm install

This is a temporary solution but it works

Angular no longer recommends npm 6 (see npm install fails with NPM 7 for more information), so the current answer is a little different.

In this particular case you can try creating a new application and have the Angular CLI skip the npm install step. With Angular 12.x, the command is ng new your-project-name --skip-install. This will still setup Git, and just require a npm install.

Before doing so, however, you'll want to determine what the issue is and fix the package.json.

This particular dependency seems to be recurring issue, as it started breaking again. See npm ERR! Could not resolve dependency: npm ERR! peer jasmine-core@">=3.8" from karma-jasmine-html-reporter@1.7.0.

For individuals coming in early July 2021, update package.json so that "jasmine-core": "~3.8.0", is listed in the package.json, and then run npm install in the root of the project directory. This should leave you ready to go, which you should be able to confirm with a ng serve --open.

The full steps:

  1. ng new your-project-name --skip-install
  2. cd your-project-name
  3. Open package.json in the editor of your choice.
  4. Edit the package.json to fix the dependency issue.
  5. npm install
  6. Fix any issues that may arise, if needed.
  7. ng serve --open to verify the project is up and running.

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

Related