无法通过 npm install axios 在 React Native 中安装 Axios

Couldn't install Axios in React Native via npm install axios

我在 React Js 中做过多次,但这是我第一次在 React Native 中使用 axios。当我通过 npm install axios 安装 axios 时,它给出了一个与其他库相关的巨大日志错误。

npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR! 
npm ERR! While resolving: react-native-location-view@0.3.0
npm ERR! Found: react-native-vector-icons@8.1.0
npm ERR! node_modules/react-native-vector-icons
npm ERR!   peer react-native-vector-icons@">7.0.0" from react-native-elements@3.4.2
npm ERR!   node_modules/react-native-elements
npm ERR!     react-native-elements@"^3.4.2" from the root project
npm ERR!   peer react-native-vector-icons@"*" from react-native-paper@4.9.2
npm ERR!   node_modules/react-native-paper
npm ERR!     react-native-paper@"^4.9.2" from the root project
npm ERR!   1 more (the root project)
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react-native-vector-icons@"^4.4.3" from react-native-location-view@0.3.0
npm ERR! node_modules/react-native-location-view
npm ERR!   react-native-location-view@"^0.3.0" from the root project
npm ERR!
npm ERR! Conflicting peer dependency: react-native-vector-icons@4.6.0
npm ERR! node_modules/react-native-vector-icons
npm ERR!   peer react-native-vector-icons@"^4.4.3" from react-native-location-view@0.3.0
npm ERR!   node_modules/react-native-location-view
npm ERR!     react-native-location-view@"^0.3.0" 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\Suyash\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\Suyash\AppData\Local\npm-cache\_logs21-12-07T15_22_51_263Z-debug.log

它本应与 React JS 相同,但由于某些原因出现了这些错误。

这不是 Axios 的问题,您的依赖项存在冲突,因为它们已过时。例如:

Could not resolve dependency:
npm ERR! peer react-native-vector-icons@"^4.4.3" from react-native-location-view@0.3.0

正在尝试拉取版本 4,而 React Native Vector Icons 在版本 9 上。您应该更新您的依赖项并相应地检查是否有任何冲突代码。还建议将 Yarn 与 React Native 结合使用。

您可以在终端中运行:

rm node_modules && rm package-lock.json && yarn install

如果你有 Yarn installed。如果如您所说一切正常,您可以尝试:

npm i react-native-location-view --legacy-peer-deps

或:

npm i --legacy-peer-deps