对于使用 create-react-app 引导的 React 17 项目,我想使用该react-helmet-async
包。该项目具有以下对等依赖项,位于package.json
文件中:
"peerDependencies": {
"react": "^16.6.0",
"react-dom": "^16.6.0"
},
尝试安装软件包时,出现以下错误:
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: project@1.0.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.6.0" from react-helmet-async@1.0.7
npm ERR! node_modules/react-helmet-async
npm ERR! react-helmet-async@"^1.0.7" 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/bas/.npm/eresolve-report.txt for a full report.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/bas/.npm/_logs/2021-02-11T13_55_56_813Z-debug.log
据我了解,react-helmet-async
对于使用此包的项目,该包需要 React ^16.6.0。我可以使用该--force
选项来消除错误,但是当我尝试执行此操作时,npm update
它会不断重复。
我尝试在我的 中添加分辨率package.json
,试图强制包使用我正在使用的 React 版本。在运行npm install
or之前npm update
,我运行了npx npm-force-resolutions
.
"resolutions": {
"react-helmet-async/react": "^17.0.1"
}
不幸的是,这没有奏效。有没有办法在不降级到 React 16 的情况下仍然使用这个包而不会在我的控制台中收到错误?另外,我是否误解了对等依赖关系?