react-native-gesture-handler: Pod install failing due to undefined 'exists' method at RNGestureHandler.podspec file

Description

Pod install keeps failing due to an undefined ‘exists’ method at RNGestureHandler.podspec file.

However the app works fine on Android, facing this error whenever I’m trying to run on ios environment.

I have checked with two of my other apps, where also I’m getting the same issue.

Here’s the error log when running pod install:


[!] Invalid `Podfile` file:
[!] Invalid `RNGestureHandler.podspec` file: undefined method `exists?' for File:Class.

 #  from /Users/user/Development/QuickMark/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/user/Development/QuickMark/ios/Podfile:8
 #  -------------------------------------------
 #  target 'quickmark' do
 >    config = use_native_modules!
 #
 #  -------------------------------------------

Steps to reproduce

  1. cd ios
  2. pod install

Snack or a link to a repository

https://github.com/ArunGovil/QuickMark

Gesture Handler version

2.8.0

React Native version

0.70.6

Platforms

iOS

JavaScript runtime

Hermes

Workflow

React Native (without Expo)

Architecture

Fabric (New Architecture)

Build type

Debug mode

Device

iOS simulator

Device model

iPhone 14

Acknowledgements

Yes

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 8
  • Comments: 20 (2 by maintainers)

Commits related to this issue

Most upvoted comments

I solved it by installing a version manager for Ruby (rbenv in my case, but you can use rvm too). I had cocoapods installed with brew previously, I removed this by running brew uninstall cocoapods. Then installed ruby version 3.1.0 with rbenv (rbenv install 3.1.0). Then ran gem install cocoapods. Works fine now.

As a workaround, if you have cocoapods installed via brew, you can patch the ruby version in the brew formula:

  1. Open a formula in vscode (for example)
HOMEBREW_EDITOR=code brew edit cocoapods
  1. Replace ruby with ruby@2.7 in lines 21 and 24 and save
19 | ...
20 |  uses_from_macos "libffi", since: :catalina
21 |  uses_from_macos "ruby@2.7", since: :catalina
22 |
23 |  on_arm do
24 |   depends_on "ruby@2.7"
25 |  end
26 | ...
  1. Reinstall cocoapods
brew reinstall --build-from-source cocoapods

In my case the problem was not only in this package, and this patch “solved” the problem for all packages.

Before #2368 gets released, this patch should do the trick:

diff --git a/RNGestureHandler.podspec b/RNGestureHandler.podspec
index fed3e8aea..fc3226de1 100644
--- a/RNGestureHandler.podspec
+++ b/RNGestureHandler.podspec
@@ -2,7 +2,7 @@ require "json"
 
 fabric_enabled = ENV['RCT_NEW_ARCH_ENABLED'] == '1'
 
-isUserApp = File.exists?(File.join(__dir__, "..", "..", "node_modules", "react-native", "package.json"))
+isUserApp = File.exist?(File.join(__dir__, "..", "..", "node_modules", "react-native", "package.json"))
 if isUserApp
   libInstances = %x[find ../../ -name "package.json" | grep "/react-native-gesture-handler/package.json" | grep -v "/.yarn/"]
   libInstancesArray = libInstances.split("\n")

Uhm, thanks for the workaround and fix, but why does a deprecated method break the whole thing? Seems to me the point of a “deprecation” is exactly to warn devs that this method might be removed in a later version, so they can adapt before the pipelines of all the non-Ruby people are broken 🤷🏻‍♂️

ruby likes to release breaking changes in minor versions, not sure why they don’t respect semver.

anyone know why the latest ruby is even used? i thought the pods installer was using system ruby?

@KiwiKilian, yes, you are right, but I chose the version recommended in the react-native documentation, currently 2.7.6

Same problem here