微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

react-helmet-async 包的 npm peer 依赖项在使用 React 17 时出错

如何解决react-helmet-async 包的 npm peer 依赖项在使用 React 17 时出错

对于使用 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 installnpm update 之前,我运行了 npx npm-force-resolutions

  "resolutions": {
    "react-helmet-async/react": "^17.0.1"
  }

这很不幸没有奏效。有没有什么方法可以在不降级到 React 16 的情况下继续使用这个包而不会在我的控制台中收到错误消息?另外,我是否误解了对等依赖项?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。