You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Macbook Air M2使用Cocoapods时RNGestureHandler.podspec无效问题仍存在

解决iOS执行pod install时的File.exists?未定义错误

问题详情

在iOS目录执行pod install时触发错误:

[!] Invalid Podfile file:
[!] Invalid RNGestureHandler.podspec file: 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 install
  • sudo arch -x86_64 gem install ffi
  • 卸载重装Homebrew、Cocoapods
  • 更新Rosetta并在Rosetta终端重装Homebrew、Cocoapods

解决方案

方法1:修改RNGestureHandler.podspec中的方法调用

File.exists?在新版Ruby中已被废弃,改用File.exist?(注意少一个s):

  1. 打开路径 /Users/placeholder/Desktop/placeholder/node_modules/react-native-gesture-handler/RNGestureHandler.podspec
  2. 找到第5行的代码:
    isUserApp = File.exists?(File.join(__dir__, "..", "..", "node_modules", "react-native", "package.json"))
    
  3. 将File.exists?替换为File.exist?,修改后代码:
    isUserApp = File.exist?(File.join(__dir__, "..", "..", "node_modules", "react-native", "package.json"))
    
  4. 保存文件后重新执行pod install

方法2:升级react-native-gesture-handler版本

该问题属于旧版本库的兼容性问题,升级到最新稳定版可解决:

  1. 在项目根目录执行:
    npm install react-native-gesture-handler@latest
    # 或使用yarn
    yarn add react-native-gesture-handler@latest
    
  2. 进入iOS目录重新执行pod install

方法3:锁定Ruby版本到兼容版本

如果不想修改库文件,可使用rbenv或rvm将Ruby版本切换到2.7.x及以上(2.6.x部分废弃方法已移除):

  1. 安装rbenv(若未安装):
    brew install rbenv
    
  2. 安装2.7.6版本Ruby:
    rbenv install 2.7.6
    
  3. 在项目根目录设置本地Ruby版本:
    rbenv local 2.7.6
    
  4. 重新执行pod install

内容的提问来源于stack exchange,提问作者user19389593

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.13 01:38:37