美文网首页RN学习日志
React Native - Git下来的项目pod失败

React Native - Git下来的项目pod失败

作者: Joh蜗牛 | 来源:发表于2022-03-17 17:38 被阅读0次

git下来的RN项目pod install失败原因:没有node_modules

问题场景

在git上拉取RN项目后,pod install的时候提示失败,如下:

$ cd ~/Desktop/RN项目/iOS
$ pod install
[!] Invalid `Podfile` file: cannot load such file -- ~/Desktop/RT项目/node_modules/@react-native-community/cli-platform-ios/native_modules.

 #  from ~/Desktop/RT项目/ios/Podfile:2
 #  -------------------------------------------
 #  platform :ios, '9.0'
 >  require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'
 #  -------------------------------------------

错误定位Invalid Podfile file: cannot load such file,分析是RN项目没有node_modules文件夹,因此PodFile执行到如下> 后语句时,执行不下去而报错。

> require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'

解决方法

1.先cd到RN项目目录下

$ cd ~/Desktop/RN项目

2.然后用npm install npm重新安装node_modules,成功后查看该项目目录下已有node_modules文件夹了

$ npm install npm

3.此时再次执行pod install,即可成功

$ cd ~/Desktop/RN项目/ios
$ pod install

(转载自:https//www.jianshu.com/p/459a5a067269)

补充:

若项目中导入新组件,会导致运行失败,应进行如下操作:
1.在项目目录:

yarn install

2.进入iOS文件:

cd ios //进入iOS文件
pod install

3.返回目录文件:

cd ../ // 返回目录文件
yarn ios

即可运行成功

相关文章

网友评论

    本文标题:React Native - Git下来的项目pod失败

    本文链接:https://www.haomeiwen.com/subject/zrzvdrtx.html