Search code examples
rubyreact-nativecocoapodshomebrewapple-m1

Invalid `Podfile` file: when I try run "pod install"


When I try to run “pod install" in the terminal, I get this same error for all my projects. Last time a complete brew update was performed.

robajz@Roberts-MacBook-Pro ios % pod install

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

 #  from /Users/robajz/Projects/shop8-mobile-app/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/robajz/Projects/shop8-mobile-app/ios/Podfile:10
 #  -------------------------------------------
 #  target 'Shop8App' do
 >    config = use_native_modules!
 #  
 #  -------------------------------------------

enter image description here


Solution

  • So after much pain, i found that if I added this line into the .podspec where the error was coming from

    print RUBY_VERSION

    It was printing out 3.2.0 which I believe has deprecated the "exists" method as mentioned in the error, but I was using a .ruby-version file and rbenv as suggested in the docs and ruby -v was printing out 2.7.5 as expected.

    After hunting through my file system to find where this v3.2.0 could possibly be installed I tried downgrading cocoapods from 1.11.3 -> 1.11.2 and it instantly solved my issue and the print in the podspec was now printing 2.7.5