错误无法解析依赖项:redux-react-session



我需要安装这个包https://www.npmjs.com/package/redux-react-session

使用npmnpm i redux-react-session安装时显示如下错误:

PS C:UsersmichaelDesktoplogin and signupclient> npm i redux-react-session
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: client@0.1.0
npm ERR! Found: react@18.1.0
npm ERR! node_modules/react
npm ERR!   react@"^18.1.0" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react@"^0.14.0 || ^15.0.0 || ^16.0.0" from redux-react-session@2.6.1
npm ERR! node_modules/redux-react-session
npm ERR!   redux-react-session@"*" 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:

{
"name": "client",
"version": "0.1.0",
"private": true,
"dependencies": {
"@emotion/react": "^11.9.0",
"@emotion/styled": "^11.8.1",
"@mui/material": "^5.8.0",
"@mui/styled-engine-sc": "^5.8.0",
"@testing-library/jest-dom": "^5.16.4",
"@testing-library/react": "^13.2.0",
"@testing-library/user-event": "^13.5.0",
"antd": "^4.20.5",
"axios": "^0.27.2",
"formik": "^2.2.9",
"react": "^18.1.0",
"react-dom": "^18.1.0",
"react-icons": "^4.4.0",
"react-loader-spinner": "^5.1.5",
"react-redux": "^8.0.2",
"react-router-dom": "^6.3.0",
"react-scripts": "5.0.1",
"redux": "^4.2.0",
"redux-thunk": "^2.4.1",
"styled-components": "^5.3.5",
"web-vitals": "^2.1.4",
"yup": "^0.32.11"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}

安装NPM包时?有两种解决方案可以解决这个问题。

解决方案1:忽略peerDependencies解决这个问题最简单的方法是向npm install传递一个额外的参数-legacy-peer-deps。--legacy-peer-deps告诉npm忽略同级依赖并继续安装包。

尝试下面的命令来安装项目的依赖项。

npm install --save --legacy-peer-deps

您也可以通过运行以下命令将其添加到配置中来永久地设置此值。

npm config set legacy-peer-deps true

注意:在这个解决方案中,默认情况下不会安装对等依赖,即使你使用的是最新版本的NPM。

方案2:Using –force另一个解决方案是使用——force标志。-f——force参数将强制npm获取远程资源,即使磁盘上存在本地副本。

步骤1:删除当前node_modules。您可以使用下面的命令删除它。

rm -rf node_modules

步骤2:移除包锁。通过运行以下命令

rm package-lock.json

步骤3:清除npm缓存,并使用——force标志执行干净安装,如下所示。

npm cache clean --force
npm install --force

通过执行上述步骤,您应该可以成功解决问题。

相关内容

  • 没有找到相关文章