Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When i run `ng new`, npm has a dependency problem [duplicate]

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: [email protected]
npm ERR! Found: [email protected]
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 [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.
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.
like image 700
Evergreen Avatar asked Jul 11 '21 18:07

Evergreen


People also ask

How do I fix dependency issues in npm?

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. Try the below command to install the dependencies for your project.

What is peer dependency npm?

A peer dependency specifies that our package is compatible with a particular version of an npm package. If a package doesn't already exist in the node_modules directory, then it is automatically added. As you install a package, npm will automatically install the dev dependencies.

What is a dependency in NPM?

A Dependency is an npm package that our package depends on in order to be able to run. Some popular packages that are typically added as dependencies are lodash, request, and moment. We add a regular dependency like this: npm adds the package name and version to the dependencies object in our project’s package.json file.

How do I resolve the upstream dependency conflict with 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 C:\Users\Kian\AppData\Local pm-cache\eresolve-report.txt for a full report. npm ERR! A complete log of this run can be found in: npm ERR!

Why do we use NPM pack?

So you use npm pack to generate an npm package from your project. You might even decide to publish it to the npm Registry. Other teams will add your package as a dependency in their own projects. We use Dependencies and Peer Dependencies in package.json to tell these other projects what packages also need to be added for our package to work.

How does NPM deal with version conflicts?

Notice that todd-b gets its own private copy of todd-child 2.0.0. npm deals with version conflicts by adding duplicate private versions of the conflicted package. As we saw from our experiment with npm version conflicts, if you add a package to your dependencies, there is a chance it may end up being duplicated in node_modules.


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.

like image 142
Samuel Sampson Avatar answered Oct 19 '22 05:10

Samuel Sampson


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

like image 27
jbacav Avatar answered Oct 19 '22 06:10

jbacav