我在尝试将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: [email protected]
npm ERR! Found: [email protected]
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 [email protected]
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"
},
看起来您正在使用最新的 npm 版本(v7)。 正如日志中提到的,尝试使用
npm install --legacy-peer-deps
npm 博客最后一次提到
--legacy-peer-deps
标志是在他们的 npm v7 测试版公开时。要了解有关该旗帜的更多信息,请访问此处。
两种方式:
npm install <package-name> --legacy-peer-deps
更好的方法是安装推荐版本的节点以适用于所有软件包。
尝试使用 Node.js 最新的“推荐给大多数用户”版本。 它对我有用
在 Mac 上尝试过,它有效。.按照升级到最新 LTS 的步骤操作
在更新 Node.js 版本之前,请检查您当前使用的版本: 节点-v
接下来,使用以下命令清除 npm 缓存: npm 缓存清理 -f
全局安装n: npm install -g n
现在您已经安装了n个,您可以使用该模块来安装Node.js的最新稳定版本: 须藤稳定
或者,您可以安装具有最新功能的 Node.js 版本:
sudo n 最新
或者,使用以下命令安装特定版本号: n [版本号]
我遇到了同样的问题,所以我运行这个命令 npm 配置设置legacy-peer-deps true
然后我简单地使用 redux 模板创建了我的 React 应用程序,如下
npx create-react-app 应用程序名称 --template redux
为我工作!!
npm 中的“legacy-peer-deps”标志提供了处理对等依赖冲突的替代解决方案。该标志允许您使用旧版本的 npm 的对等依赖解析算法来安装软件包。
尝试运行命令 npm install --save redux-devtools-extension --legacy-peer-deps
有点晚了,但您可以使用
--force
或 --legacy-peer-deps
选项解决此问题。两者都应该按照 npm
报告的错误中提到的方式工作
尝试用纱线添加它。为我工作