Macbook Air M2使用Cocoapods时RNGestureHandler.podspec无效问题仍存在
解决iOS执行
pod install时的File.exists?未定义错误 问题详情
在iOS目录执行pod install时触发错误:
[!] Invalid
Podfilefile:
[!] InvalidRNGestureHandler.podspecfile: undefined method `exists?' for File:Class.from /Users/placeholder/Desktop/placeholder/node_modules/react-native-gesture-handler/RNGestureHandler.podspec:5-------------------------------------------> isUserApp = File.exists?(File.join(dir, "..", "..", "node_modules", "react-native", "package.json"))
if isUserApp-------------------------------------------.
from /Users/placeholder/Desktop/placeholder/ios/Podfile:14-------------------------------------------use_expo_modules!> config = use_native_modules!
设备及环境:
- M2芯片Macbook Air,Ventura系统
- Ruby: ruby 2.6.10p210 (2022-04-12 revision 67958) [arm64-darwin22]
- Homebrew: 4.1.5
- Cocoapods: 1.12.1
已尝试无效操作:
arch -x86_64 pod installsudo arch -x86_64 gem install ffi- 卸载重装Homebrew、Cocoapods
- 更新Rosetta并在Rosetta终端重装Homebrew、Cocoapods
解决方案
方法1:修改RNGestureHandler.podspec中的方法调用
File.exists?在新版Ruby中已被废弃,改用File.exist?(注意少一个s):
- 打开路径
/Users/placeholder/Desktop/placeholder/node_modules/react-native-gesture-handler/RNGestureHandler.podspec - 找到第5行的代码:
isUserApp = File.exists?(File.join(__dir__, "..", "..", "node_modules", "react-native", "package.json")) - 将
File.exists?替换为File.exist?,修改后代码:isUserApp = File.exist?(File.join(__dir__, "..", "..", "node_modules", "react-native", "package.json")) - 保存文件后重新执行
pod install
方法2:升级react-native-gesture-handler版本
该问题属于旧版本库的兼容性问题,升级到最新稳定版可解决:
- 在项目根目录执行:
npm install react-native-gesture-handler@latest # 或使用yarn yarn add react-native-gesture-handler@latest - 进入iOS目录重新执行
pod install
方法3:锁定Ruby版本到兼容版本
如果不想修改库文件,可使用rbenv或rvm将Ruby版本切换到2.7.x及以上(2.6.x部分废弃方法已移除):
- 安装rbenv(若未安装):
brew install rbenv - 安装2.7.6版本Ruby:
rbenv install 2.7.6 - 在项目根目录设置本地Ruby版本:
rbenv local 2.7.6 - 重新执行
pod install
内容的提问来源于stack exchange,提问作者user19389593
相关产品推荐
相关产品推荐

