我试图安装Stripe NPM软件包到反应项目使用npm,但无法安装它。这是显示在终端上的错误。
PS C:\Users\adity\OneDrive\Desktop\stripe-payments> npm i @stripe/react-stripe-js
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: stripe-payments@0.1.0
npm ERR! Found: react@18.0.0
npm ERR! node_modules/react
npm ERR! react@"^18.0.0" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react@"^16.8.0 || ^17.0.0" from @stripe/react-stripe-js@1.7.0
npm ERR! node_modules/@stripe/react-stripe-js
npm ERR! @stripe/react-stripe-js@"*" 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 C:\Users\adity\AppData\Local\npm-cache\eresolve-report.txt for a full report.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\adity\AppData\Local\npm-cache\_logs\2022-03-31T12_21_47_015Z-debug-0.log发布于 2022-03-31 14:06:03
您可以在安装--force时尝试使用它,因为它似乎想要React v17或v16,但是您目前的反应是v18。我不建议使用--force,因为它可能会在将来导致一些依赖错误的中断,不过,就我所能测试的范围而言,它工作得很好:
npm install @stripe/react-stripe-js @stripe/stripe-js --force
或者,您可以将您的React应用程序的版本更改为v17,因为v18是非常新的,而且npm上的大多数组件可能会使用v16和v17。您可以通过转到您的package.json并在那里手动更改版本来做到这一点。(由于某些原因,无法使用手动安装reason。)在这篇文章中,here对此作了解释。
如果您正在使用webpack (或者您安装它时没有使用npx create-react-app ),您可以始终使用以下方法安装react:
npm i react@<your version here> react-dom@<your version here>
它应该能够很好地工作,没有任何依赖错误。
发布于 2022-03-31 13:44:40
尝试运行npm install @stripe/react-stripe-js --force或npm install @stripe/react-stripe-js --legacy-peer-deps
如果不起作用,则删除节点模块文件夹,并使用上述命令恢复所有依赖项。
如果它仍然不起作用,你将不得不将你的反应版本从18降到17或16
https://stackoverflow.com/questions/71692454
复制相似问题