Unable to Pod Install on a brand new React Native Project
Asked Answered
P

5

9

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?

Pecuniary answered 29/1, 2023 at 17:49 Comment(4)
Your RN version should be 0.71.1 in your package.json, is it?Liesa
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 againPecuniary
It has to be 71.1 to have the right scripts for the Podfile.Liesa
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. github.com/facebook/react-native/commit/…Lemures
R
13

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!

Roney answered 1/2, 2023 at 8:45 Comment(4)
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-installCordwain
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.Lemures
@Lemures this is the temp fix (hot fix) because of upgrading new RN, for a long time RN fixed this bug.Roney
I agree with @Jon, I've removed the variable and just hard-coded the value to '13'Shopworn
E
12

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!

Erland answered 26/8, 2023 at 13:43 Comment(1)
Yep nice solution! If react-native required a newer version, it will take that automatically. ThxDigestion
H
6

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.

Hallo answered 19/6, 2023 at 11:53 Comment(0)
E
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'
Evaluate answered 23/2, 2023 at 10:13 Comment(1)
Thanks, I was missing those "require" statements, and that was the reason why the "min_ios_version_supported" variable was not valid.Lemures
T
2

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.

Trafalgar answered 30/3, 2023 at 18:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.