在终端 Visual Studio 代码上安装 React-Reveal 动画时出现问题

Seb*_*ien 4 npm reactjs

大家好,我有一个安装react-reveal动画依赖项的探针,每次我输入这个命令(npm install react-reveal --save)时我都会遇到这个问题,并且我不知道如何解决这个问题,如果一个人遇到过这个问题或者知道如何解决这个问题。可以帮助我,谢谢。

npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! While resolving: portfolio-sebastien@0.1.0
npm ERR! Found: react@17.0.2
npm ERR! node_modules/react
npm ERR!   react@"^17.0.2" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react@"^15.3.0 || ^16.0.0" from react-reveal@1.2.2
npm ERR! node_modules/react-reveal
npm ERR!   react-reveal@"*" 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/sebastienfirouzfar/.npm/eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/sebastienfirouzfar/.npm/_logs/2021-06-17T08_40_33_036Z-debug.log
Run Code Online (Sandbox Code Playgroud)

小智 11

这是因为 React-reveal 已经大约 4 年没有更新了,你可以在这里看到https://github.com/rnosov/react-reveal。它的依赖项正在寻找 React 15 或 16。您有 React v17,因此它会抛出一个错误,表明它可能不适用于该版本。

我可以确认,react-reveal 在 React v17 上对我来说效果很好。但是您需要使用以下命令安装react-reveal npm i react-reveal --legacy-peer-deps:。或者,如果您的 package.json 中已有软件包,那么您可以使用 来安装所有内容而不会出现错误npm i --legacy-peer-deps

另一种选择是您可以放弃react-reveal并使用react-awesome-reveal代替。这个包对 React 做了类似的 fade 和 Reveal,但它的 API 略有不同,并且不具备 React-Reveal 的所有高级功能。如果您只使用react-reveal的基本功能,这只是一个替代品。