尝试安装 react-redux 依赖项时出错

新手上路,请多包涵

我在尝试将 react-redux 包安装到我的 create-react-app 应用程序时遇到错误。我已尝试删除并重新安装我的 node_modules 文件夹以及使用管理员权限安装它,但我仍然收到相同的错误

➜  frontend git:(main) ✗ npm i react-redux
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree

这是控制台的剩余输出

npm ERR!
npm ERR! While resolving: frontend@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!
npm ERR! Could not resolve dependency:
npm ERR! peer react@"^16.8.3" from react-redux@7.2.1
npm ERR! node_modules/react-redux
npm ERR!   react-redux@"*" 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.

这是我的 package.json 中当前依赖项的列表

 "dependencies": {
    "@testing-library/jest-dom": "^4.2.4",
    "@testing-library/react": "^9.5.0",
    "@testing-library/user-event": "^7.2.1",
    "axios": "^0.21.0",
    "react": "^17.0.1",
    "react-bootstrap": "^1.4.0",
    "react-dom": "^17.0.1",
    "react-router-bootstrap": "^0.25.0",
    "react-router-dom": "^5.2.0",
    "react-scripts": "3.4.4",
    "redux": "^4.0.5",
    "redux-devtools-extension": "^2.13.8",
    "redux-thunk": "^2.3.0",
    "tachyons": "^4.12.0"
  },

原文由 Moose Hamid 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 2.3k
2 个回答

看起来您正在使用最新的 npm 版本 (v7)。如日志中所述,尝试使用 npm install --legacy-peer-deps


上次 npm 博客提到 --legacy-peer-deps 标志是在他们的 npm v7 测试版公开时。要了解更多关于标志的信息,请 点击此处

原文由 Alexandre 发布,翻译遵循 CC BY-SA 4.0 许可协议

两种方式:

  1. npm install <package-name> --legacy-peer-deps
  2. 为大多数用户安装推荐的节点版本

更好的方法是安装推荐版本的节点以适用于所有包。

原文由 Alireza Piran 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
logo
Stack Overflow 翻译
子站问答
访问
宣传栏