无法安装react-paypal-button-v2



我正在学习电子商务教程,不像讲师,我不能安装react-paypal-button-v2。

我的错误日志是

npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! While resolving: frontend@0.1.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@"^0.14.6 || 15.x.x || 16.x.x" from react-paypal-button-v2@2.6.2
npm ERR! node_modules/react-paypal-button-v2
npm ERR!   react-paypal-button-v2@"*" 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.

如果有用的话,这是我的包裹。json文件:

{
"name": "frontend",
"proxy": "http://localhost:8000",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
"axios": "^0.21.1",
"dotenv": "^8.2.0",
"moment": "^2.29.1",
"react": "^17.0.1",
"react-bootstrap": "^1.4.3",
"react-dom": "^17.0.1",
"react-redux": "^7.2.2",
"react-router-bootstrap": "^0.25.0",
"react-router-dom": "^5.2.0",
"react-scripts": "4.0.1",
"redux": "^4.0.5",
"redux-devtools-extension": "^2.13.8",
"redux-thunk": "^2.3.0",
"web-vitals": "^0.2.4"
},
"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"
]
}
}

我很困惑,因为我和教练有完全相同的依赖树,唯一的区别是我安装了momentdotenv,他在PC上运行,我在Mac上运行,但他安装它没有问题。

该教程是最近的(不到一个月),并且在他的包中的版本。Json和我的基本相同。

我发现了这个开放的问题,但是它还没有被开发人员解决。

我很想知道如何解决这个问题并继续下去,我相信它也会帮助我在未来如何对这些错误进行分类。

谢谢!

尝试强行使用install by using--forcein your command.

npm install react-paypal-button-v2 --force

这是npm的一个问题。你可以用yarn安装它,它会工作的很好。

yarn add react-paypal-button-v2

纱线安装步骤

这个库的问题通常与React版本的兼容性有关。如果遇到兼容性问题,请检查这个。

npm install react-paypal-button-v2 --legacy-peer-deps

它也有另一种回答方式,正如您在错误中看到的那样. 这是一个依赖冲突版本之间。根据错误,react-paypal-button-v2有一个对等依赖.

这意味着:

期望一个特定的版本或版本范围

如你所见,你的包有对等依赖onReactjs.
peer react@"^0.14.6 || 15.x.x || 16.x.x

因此,更改版本可能会有所帮助。关于你的错误,上面写的是0.14.6 || 15.x.x || 16.x.x。所有版本的React都可以接受或与您的包兼容,但根据您的错误,它可能与React版本17.x.x或更高版本不兼容。

最新更新