安装软件包时,ERESOLVE无法解析依赖树。

18
在使用npm install为我的项目安装依赖项时,我遇到了一个错误,但我不知道如何解释它:
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! While resolving: soft-ui-dashboard-pro-react@3.1.0
npm ERR! Found: react@17.0.2
npm ERR! node_modules/react
npm ERR!   react@"17.0.2" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer react@"^0.14.9 || ^15.3.0 || ^16.0.0" from react-quill@1.3.5
npm ERR! node_modules/react-quill
npm ERR!   react-quill@"1.3.5" 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/amin/.npm/eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/amin/.npm/_logs/2022-03-23T05_47_43_419Z-debug-0.log

这些是package.json中的依赖项:
  "dependencies": {
    "@asseinfo/react-kanban": "2.2.0",
    "@emotion/cache": "11.7.1",
    "@emotion/react": "11.8.1",
    "@emotion/styled": "11.8.1",
    "@fullcalendar/daygrid": "5.10.1",
    "@fullcalendar/interaction": "5.10.1",
    "@fullcalendar/react": "5.10.1",
    "@fullcalendar/timegrid": "5.10.1",
    "@mui/icons-material": "5.4.2",
    "@mui/material": "5.4.3",
    "@mui/styled-engine": "5.4.2",
    "@pathofdev/react-tag-input": "1.0.7",
    "@react-leaflet/core": "1.1.1",
    "@testing-library/jest-dom": "5.16.2",
    "@testing-library/react": "12.1.3",
    "@testing-library/user-event": "13.5.0",
    "@three-ts/orbit-controls": "1.4.7",
    "chart.js": "3.4.1",
    "chroma-js": "2.4.2",
    "dropzone": "5.9.3",
    "flatpickr": "4.6.9",
    "formik": "2.2.9",
    "html-react-parser": "1.4.8",
    "leaflet": "1.7.1",
    "prop-types": "15.8.1",
    "react": "17.0.2",
    "react-chartjs-2": "3.0.4",
    "react-circular-slider-svg": "0.1.5",
    "react-countup": "6.1.1",
    "react-dom": "17.0.2",
    "react-flatpickr": "3.10.7",
    "react-github-btn": "1.2.1",
    "react-images-viewer": "1.7.1",
    "react-leaflet": "3.2.5",
    "react-quill": "1.3.5",
    "react-router-dom": "6.2.1",
    "react-scripts": "5.0.0",
    "react-select": "5.2.2",
    "react-table": "7.7.0",
    "stylis": "4.0.13",
    "stylis-plugin-rtl": "2.1.1",
    "sweetalert2": "11.4.4",
    "three": "0.121.1",
    "uuid": "8.3.2",
    "vanilla-tilt": "1.7.2",
    "web-vitals": "2.1.4",
    "yup": "0.32.11"
  },
9个回答

33

这意味着您存在依赖冲突。请尝试逐个运行以下选项。

1. 删除 node_modulespackage-lock.json 然后运行

 npm install

2. 或者尝试清除 npm 缓存

npm cache clean --force

3. 或者使用 --legacy-peer-deps 选项运行命令

npm install --legacy-peer-deps

4. 或者使用 --force 选项运行命令

npm install --force

13
这个东西不起作用,为什么这被接受为答案?npm/node太疯狂了...更新包像火箭科学一样复杂。 - uberrebu
@uberrebu 那正确答案是什么? - NewUser134
它确实有效,但这取决于每个案例的具体情况,对于你的具体冲突可能不适用(#3对我来说非常有效)。 - undefined

30
  1. Remove node_modules

    rm -rf node_modules
    
  2. Set this

    npm config set legacy-peer-deps true
    
  3. Install npm

    npm install
    

这实际上应该是被接受的答案!谢谢。 - AlexioVay
这个修复了问题。 - Ranjithkumar
这实际上是做什么的? - Gav Hern
可能是错的,但我不认为这应该被接受作为答案,因为它没有解决问题的根本,并且会引导错误。通过使用legacy-peer-deps,我们可能会破坏某些东西。https://dev59.com/WlEG5IYBdhLWcg3wbNMC - DanielPanic
如果您想为特定项目设置此npm配置,请导航到其根目录,并执行npm config set legacy-peer-deps true --global false - Jimmy

4
请注意在运行npm install <package>时使用--force--legacy-peer-deps选项,这可能会导致问题。相反,我们应该解决依赖包之间的版本兼容性问题。
警告意味着react-quill@1.3.5包要求与其兼容的react版本作为其对等依赖项。我们如何知道哪些版本是兼容的?
下面的命令将检查package.json文件中的peerDependencies字段。
$ npm view react-quill@1.3.5 peerDependencies
{ react: '^0.14.9 || ^15.3.0 || ^16.0.0' }

正如您所看到的,兼容的React版本为:'^0.14.9 || ^15.3.0 || ^16.0.0'。但是您在项目中安装了react: 17.0.2。这就是您收到警告的原因。

两个安全的解决方案:

  • react包降级至这些兼容版本,您可以使用16.x的最新版本。您可以通过运行以下命令来找到它:
$ npm view react@16 version
react@16.0.0 '16.0.0'
react@16.1.0 '16.1.0'
react@16.1.1 '16.1.1'
react@16.2.0 '16.2.0'
react@16.3.0 '16.3.0'
react@16.3.1 '16.3.1'
react@16.3.2 '16.3.2'
react@16.4.0 '16.4.0'
react@16.4.1 '16.4.1'
react@16.4.2 '16.4.2'
react@16.5.0 '16.5.0'
react@16.5.1 '16.5.1'
react@16.5.2 '16.5.2'
react@16.6.0 '16.6.0'
react@16.6.1 '16.6.1'
react@16.6.2 '16.6.2'
react@16.6.3 '16.6.3'
react@16.7.0 '16.7.0'
react@16.8.0 '16.8.0'
react@16.8.1 '16.8.1'
react@16.8.2 '16.8.2'
react@16.8.3 '16.8.3'
react@16.8.4 '16.8.4'
react@16.8.5 '16.8.5'
react@16.8.6 '16.8.6'
react@16.9.0 '16.9.0'
react@16.10.0 '16.10.0'
react@16.10.1 '16.10.1'
react@16.10.2 '16.10.2'
react@16.11.0 '16.11.0'
react@16.12.0 '16.12.0'
react@16.13.0 '16.13.0'
react@16.13.1 '16.13.1'
react@16.14.0 '16.14.0'

$ npm install react@^16.14.0 react-dom@^16.14.0 -S

使用与react v17兼容的react-quill@2版本,查看其peer dependencies。
$ npm view react-quill@2 peerDependencies
{ react: '^16 || ^17 || ^18', 'react-dom': '^16 || ^17 || ^18' }

3

以上方法都没有帮到我,解决方法是,我切换了使用sass而不是node-sass,并且从React 17改用React 16。由于node-sass已经被弃用,所以请使用sass代替(npm install sass)。这对我有效。太棒了!


1
我的问题是我同时使用了yarn和npm,所以我删除了package-json.lock、node_modules和yarn.lock文件,然后用yarn install重新安装。

0

请按照以下步骤操作:

  1. 删除 node_modules 文件夹
  2. 删除 package-lock.json 文件
  3. 运行 npm install --force

0
首先,你需要在终端中运行以下命令:
``` npm config set legacy-peer-deps true ```
然后尝试安装包,这应该解决问题。

这个答案与这个答案相同或非常相似。最好是给那个答案点赞,而不是再次发布它。在网站上投入一些时间,你将获得足够的特权,可以为帮助过你的答案点赞。 - LW001

0
我不得不卸载导致问题的软件包,安装新的软件包,并重新安装之前卸载的软件包。

0

一行简单的代码

rm -f -- package-lock.json && rm -rf node_modules && npm i --legacy-peer-deps

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接