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

时间:2020-10-25 23:45:15

标签: node.js reactjs npm 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"
  },

6 个答案:

答案 0 :(得分:16)

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


npm博客最后一次提到--legacy-peer-deps标志是在其beta版本的npm v7公开之时。要了解有关该标志的更多信息,请访问here

答案 1 :(得分:11)

尝试安装推荐的 nodejs 版本(下面的屏幕截图)。哪个应该可以解决这个问题。

enter image description here

这里重现了此错误及其解决方案(以下屏幕截图):

问题:

Nodejs:最新功能:

enter image description here

解决方案:

Nodejs:推荐给大多数用户:

enter image description here

安装 node js 的推荐版本立即修复了这个问题,允许安装相关的依赖项。

如果您遇到本机依赖的问题,那么一旦安装了推荐的版本,请务必更新您的 pod 文件。

答案 2 :(得分:3)

尝试使用 Node.js 最新的“推荐给大多数用户”版本。 它对我有用

答案 3 :(得分:2)

在 Mac 上尝试过,它有效.. 按照升级到最新 LTS 的步骤

  1. 在更新 Node.js 版本之前,请检查您当前使用的是哪个版本: 节点 -v

  2. 接下来,使用以下命令清除 npm 缓存: npm 缓存清理 -f

  3. 全局安装 n: npm install -g n

  4. 现在您已经安装了 n,您可以使用该模块来安装 Node.js 的最新稳定版本: 须藤稳定

或者,您可以安装具有最新功能的 Node.js 版本:

sudo n 最新

或者,安装特定版本号: n [版本号]

答案 4 :(得分:0)

两种方式:

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

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

答案 5 :(得分:-3)

尝试用纱线添加它。为我工作