繁体   English   中英

如何解决此 npm 安装依赖问题?

[英]How to fix this npm install dependency issue?

我正在尝试将npm install react-material-ui-carousel --save添加到我的反应项目中。 但是,当我尝试安装时,我得到了这个依赖树问题。

  • 我已经删除了锁和 npm 模块文件,然后是npm install整个项目。 然而,下面仍然出现同样的错误。
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! While resolving: buckets@0.1.0
npm ERR! Found: react@17.0.1
npm ERR! node_modules/react
npm ERR!   react@"^17.0.1" from the root project
npm ERR!   peer react@"^16.8.0 || ^17.0.0" from @material-ui/core@4.11.3
npm ERR!   node_modules/@material-ui/core
npm ERR!     @material-ui/core@"^4.11.2" from the root project
npm ERR!     peer @material-ui/core@"^4.9.11" from react-material-ui-carousel@2.2.1
npm ERR!     node_modules/react-material-ui-carousel
npm ERR!       react-material-ui-carousel@"*" from the root project
npm ERR!     1 more (@material-ui/icons)
npm ERR!   2 more (react-dom, @material-ui/icons)
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer react@"^16.13.1" from react-material-ui-carousel@2.2.1
npm ERR! node_modules/react-material-ui-carousel
npm ERR!   react-material-ui-carousel@"*" 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/user/.npm/eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/user/.npm/_logs/2021-03-02T19_57_57_671Z-debug.log

我的其他依赖项:

{
  "name": "app",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@material-ui/core": "^4.11.2",
    "@material-ui/icons": "^4.11.2",
    "@material-ui/lab": "^4.0.0-alpha.57",
    "@reduxjs/toolkit": "^1.5.0",
    "@testing-library/jest-dom": "^5.11.6",
    "@testing-library/react": "^11.2.2",
    "@testing-library/user-event": "^12.6.0",
    "axios": "^0.21.1",
    "chartist": "^0.10.1",
    "react": "^17.0.1",
    "react-chartist": "^0.14.4",
    "react-dom": "^17.0.1",
    "react-hook-form": "^6.14.2",
    "react-redux": "^7.2.2",
    "react-router-dom": "^5.2.0",
    "react-scripts": "4.0.1",
    "react-window": "^1.8.6",
    "redux": "^4.0.5",
    "redux-persist": "^6.0.0",
    "web-vitals": "^0.2.4"
  },

我可以尝试的另一个选项是--legacy-peer-deps ,但如果没有其他方法,我只会将其作为最后一个结果选项。

如何正确修复依赖树错误以将react-material-ui-carousel安装到我的项目中?

在命令末尾添加--force--legacy-peer-deps 像这样: npm install react-material-ui-carousel --save --legacy-peer-deps

"peerDependencies":{ "react": "^17.0.1"} 将此添加到您的 package.json

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM