3

I am running on an M1 Mac, and after following all of the instructions here, I am unable to run any form of pod install. When I do, I am given the following error...

[!] Invalid `Podfile` file: undefined local variable or method
`min_ios_version_supported' for #<Pod::Podfile:0x000000010ed18c60>.

I've tried running bundle install followed by bundle exec pod install, but I am faced then with the same error.

I use yarn instead of npm, I've tried removing the node_modules and running yarn cache clean as per some other answer on this site, though I did not truly expect those to work.

Additionally, my Podfile does contain the needed imports at the top of the file...

require_relative '../node_modules/react-native/scripts/react_native_pods'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'

I've even tried to just manually enter a min_ios_version_supported at 12.4 because that is what my most recent project is working on. That gave me a different error, which I fixed again with a manual value entry, but that gave me a different more complicated error, essentially telling me I am better off actually solving the issue instead of patching it.

Finally, I've tried adding the react-native.config.js file. Still receiving the same error

I've made plenty of React Native projects before, and noticed that this Podfile on my brand new project looks very different than Podfiles I've used in the past-- am I on a new version of React that is not yet optimized?

halfer
  • 19,824
  • 17
  • 99
  • 186
TheMilkMan
  • 143
  • 2
  • 7
  • Your RN version should be 0.71.1 in your package.json, is it? – Abe Jan 30 '23 at 03:38
  • It was initially, I tried rolling it back to 0.69 but it provided the same error. Something must have gone wrong with the project's initialization, I just abandoned it and started from scratch again – TheMilkMan Jan 30 '23 at 16:14
  • It has to be 71.1 to have the right scripts for the Podfile. – Abe Jan 30 '23 at 17:59
  • Starting with RN 0.71, the supported iOS version is no longer directly defined in Podfile. This simplifies the setup by allowing RN to manage the supported version. https://github.com/facebook/react-native/commit/34fafb2b881751cdd998d7d5ef486d536607c9ce – Jon Apr 05 '23 at 01:05

5 Answers5

7

At Podfile, min_ios_version_supported is in

require_relative '../node_modules/react-native/scripts/react_native_pods'

So, in '../node_modules/react-native/scripts/react_native_pods', you change at line 29:

def min_ios_version_supported
  return '12.4'
end

to

def min_ios_version_supported
  return '13.0'
end

After that, delete Podfile.lock, Pods and pod install again!

Good luck!

Mien PV
  • 110
  • 3
  • This happened to me after RN upgrade to 0.71.3 using Upgrade Helper. I just ran npm install and after that i ran: npx pod-install – Adnan Erkocevic Mar 09 '23 at 07:44
  • 4
    This is not the right answer. The files in the node-modules directory are controlled by npm. Any changes you make there will be overwritten the next time you run `npm i`. – Jon Apr 04 '23 at 19:19
  • @Jon this is the temp fix (hot fix) because of upgrading new RN, for a long time RN fixed this bug. – Mien PV Apr 05 '23 at 14:17
  • I agree with @Jon, I've removed the variable and just hard-coded the value to '13' – GeekDev Jun 17 '23 at 11:14
3

In My Case, It worked after I moved below two lines to the top of the Podfile.

require_relative '../node_modules/react-native/scripts/react_native_pods'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'
Rohit Ninawe
  • 41
  • 1
  • 3
  • Thanks, I was missing those "require" statements, and that was the reason why the "min_ios_version_supported" variable was not valid. – Jon Apr 05 '23 at 00:59
3

can't we just replace Podfile with this?

platform :ios, '13.0'

The min_ios_version_supported is a managed property that depends on the version of react-native and changing it with hard coding can cause issues later on depending on your development environment.

If you need version 13.0, just specify it in your Podfile.

enoveh
  • 103
  • 7
1

Silly me, in my case, I wanted to upgrade react native to 0.71.4 and I changed that manually in package.json. The error happened when I tried pod install before running yarn install.

Running yarn install and only then pod install fixed the issue for me. Hope this helps somebody.

Ovidiu Cristescu
  • 821
  • 7
  • 19
1

I do not really like the idea to change something in node_modules folder. Just try to use this approach:

min_ios_versions_supported = ['13.0', min_ios_version_supported]
index_of_max = min_ios_versions_supported.each_with_index.max_by { |number, _| number.to_f }[1]
platform :ios, min_ios_versions_supported[index_of_max]

You may set any your min_ios_version_supported (here '13.0') and min_ios_version_supported (from RN) as is. Then just choose the max of them. Profit!

Vitalii Obideiko
  • 1,726
  • 1
  • 13
  • 16