无法通过 npm install axios 在 React Native 中安装 Axios
Posted
技术标签:
【中文标题】无法通过 npm install axios 在 React Native 中安装 Axios【英文标题】:Couldn't install Axios in React Native via npm install axios 【发布时间】:2022-01-12 16:28:02 【问题描述】:我在 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\_logs\2021-12-07T15_22_51_263Z-debug.log
它应该与 React JS 相同,但由于某种原因出现了这些错误。
【问题讨论】:
虽然应用程序与所有这些库都可以正常工作。 【参考方案1】:这不是 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
【讨论】:
好的!我会试试这个。让我们希望它有效。谢谢 不,它没有用。我更新了每个库,但还是一样。 @SuyashVashishtha 使用--legacy-peer-deps
进行了编辑
@DarthVader 谢谢!那行得通。
请将其标记为已接受的答案。以上是关于无法通过 npm install axios 在 React Native 中安装 Axios的主要内容,如果未能解决你的问题,请参考以下文章
无法运行“npm install expo-cli --global”