NodeJS 面对npm i和安装npm软件包的问题

uurity8g  于 2022-12-26  发布在  Node.js
关注(0)|答案(2)|浏览(225)

嗨,我试图通过NPM安装NPM包我,但是我不断得到这个错误:

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

这是我的package.json文件:

{
  "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"
  }
}

不知道问题到底是什么,但每次我试图安装一个软件包或只是纯粹运行npm i,我得到上面的错误,如果有人能帮助我会很感激吗?

chhqkbe1

chhqkbe11#

如果在运行npm install时出现任何问题,请尝试运行yarn install命令,以查找哪个软件包有问题或依赖性,yarn install命令将为开发人员给予安装问题的明确想法,您可以在以下警告中找到这些问题
警告“〉@cypress/react@5.12.5”具有未满足的对等依赖项“react@^=16.x|| ^=17.x”. warning“〉@cypress/react@5.12.5”具有未满足的对等依赖项“react-dom@^=16.x|| ^=17.x”.警告“〉@cypress/vite-dev-server@2.2.3”具有未满足的对等依赖关系“vite@〉= 2.1.3”。警告“〉webpack-dev-server@4.9.3”具有未满足的对等依赖关系“webpack@^4.37.0|| ^5.0.0”.警告“webpack-dev-server〉webpack-dev-middleware@5.3.3”具有未满足的对等依赖项“webpack@^4.0.0|| ^5.0.0”。

使用以下配置解决上述问题

"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"
  }
nx7onnlm

nx7onnlm2#

此问题可能与cypress-image-snapshot软件包的peerDependencies有关。
peerDependencies的外观如下所示:

"peerDependencies": {
 "cypress": "^4.5.0"
}

但在编写此响应时,cypress的当前版本是12.2.0--〉https://github.com/cypress-io/cypress/releases
cypress-image-snapshot似乎需要更新peerDependencies
我发现this issue与您遇到的问题类似。另外,上次更新库是在Jan 222
变通方案可以是运行npm install --legacy-peer-deps,但这并不能解决真实的的问题。

相关问题