Facing issues with npm i and installing npm packages

Viewed 344

Hi I'm trying to install NPM package via NPM I, however I constantly get this error:

npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR! 
npm ERR! While resolving: cypress-image-snapshot@4.0.1
npm ERR! Found: cypress@9.6.0
npm ERR! node_modules/cypress
npm ERR!   dev cypress@"9.6.0" from the root project
npm ERR!   peer cypress@"*" from @cypress/code-coverage@3.9.12
npm ERR!   node_modules/@cypress/code-coverage
npm ERR!     dev @cypress/code-coverage@"^3.9.12" from the root project
npm ERR!   2 more (@cypress/react, cypress-expect)
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer cypress@"^4.5.0" from cypress-image-snapshot@4.0.1
npm ERR! node_modules/cypress-image-snapshot
npm ERR!   dev cypress-image-snapshot@"^4.0.1" from the root project
npm ERR! 
npm ERR! Conflicting peer dependency: cypress@4.12.1
npm ERR! node_modules/cypress
npm ERR!   peer cypress@"^4.5.0" from cypress-image-snapshot@4.0.1
npm ERR!   node_modules/cypress-image-snapshot
npm ERR!     dev cypress-image-snapshot@"^4.0.1" 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/2022-04-29T10_17_53_835Z-debug-0.log

This is my package.json file:

{
  "scripts": {
    "cy:run": "cypress run",
    "cy:open": "cypress open"
  },
  "devDependencies": {
    "@cypress/code-coverage": "^3.9.12",
    "cypress": "9.6.0",
    "cypress-expect": "^2.5.2",
    "cypress-image-snapshot": "^4.0.1"
  },
  "dependencies": {
    "@cypress/react": "^5.12.4",
    "@cypress/vite-dev-server": "^2.2.2",
    "webpack-dev-server": "^4.8.1"
  },
  "engines": {
    "node": ">=18.0.0"
  }
}

Not sure what the problem is exactly, but everytime i try to install a package or just purely run npm i, I get the above error, would appreciate it if someone can help?

1 Answers

if there is any issue in running npm install , try to run yarn install command to find which package has problem or dependency,yarn install command will give clear idea to the developer on issue's for installing , you can find them in the warnings as below

warning " > @cypress/react@5.12.5" has unmet peer dependency "react@^=16.x || ^=17.x". warning " > @cypress/react@5.12.5" has unmet peer dependency "react-dom@^=16.x || ^=17.x". warning " > @cypress/vite-dev-server@2.2.3" has unmet peer dependency "vite@>= 2.1.3". warning " > webpack-dev-server@4.9.3" has unmet peer dependency "webpack@^4.37.0 || ^5.0.0". warning "webpack-dev-server > webpack-dev-middleware@5.3.3" has unmet peer dependency "webpack@^4.0.0 || ^5.0.0".

use below configuration to resolve the above issue

"scripts": {
    "cy:run": "cypress run",
    "cy:open": "cypress open"
  },
  "devDependencies": {
    "@cypress/webpack-dev-server": "^2.0.0",
    "@cypress/react": "^6.0.0",
    "@types/cypress-image-snapshot": "^3.1.4",
    "@cypress/code-coverage": "^3.9.12",
    "cypress": "^9.6.0",
    "cypress-expect": "^2.5.2"
  },
  "dependencies": {
    "@cypress/vite-dev-server": "^2.2.2"
  },
  "engines": {
    "node": ">=18.0.0"
  }
Related