1 minute read

I recently received a new MacBook M2 air and was excited to start installing development tools and running my first builds. However, when I tried to build my React Native Expo project, it failed with an error during pod install

expo run:ios

⚠️  Something went wrong running `pod install` in the `ios` directory.
Command `pod install` failed.
└─ Cause: Invalid `Podfile` file: undefined method `exists?' for File:Class.

 #  from /Users/andrew/deepeyes/test-app/ios/Podfile:13
 #  -------------------------------------------
 #  target 'testapp' do
 >    use_expo_modules!
 #    config = use_native_modules!
 #  -------------------------------------------

I searched online for a solution to this error, but couldn’t find any information. So, I created an issue on the Expo GitHub repository. After a couple of days without a response, I was surprised to see that other people had encountered the same issue and even provided workarounds and the root cause of the problem. There were so many knowledgeable and kind people who shared their findings.

The root cause of the issue was the latest breaking change in Ruby 3.2. Ruby is known for its frequent breaking changes in order to improve quickly. File.exists? was removed in Ruby 3.2.

A workaround for this issue is to install Ruby 3.1 instead.

dbrezack shared his workaround:

Here is the work around if don't have time to wait on a fix

brew install ruby@3.1
Add that ruby@3.1 to path (At the front)
gem install cocoapods
gem env find the EXECUTABLE_DIRECTORY for the gem env
put result from 4 in path

sergged provided a more detailed explanation for those who are not as familiar with Ruby and bash:

Thank you! It works. You are Genius!

As a hint for someone who is not familiar (as I was as a new mac user) and using default homerew and shell settings:

brew install ruby@3.1
echo 'export PATH="/opt/homebrew/opt/ruby@3.1/bin:$PATH"' >> ~/.zshrc
gem install cocoapods
echo 'export PATH="/opt/homebrew/lib/ruby/gems/3.1.0/bin:$PATH"' >> ~/.zshrc

Finally, the issue was resolved and I am very grateful to everyone who helped with it