Fix: undefined local variable or method 'config' for Podfile in React Native
How to resolve the 'config' variable scope issue when upgrading React Native to 0.76
Context#
- Upgrading React Native 0.72 → 0.76
- Building for iOS Simulator using Xcode 16.4
- Running
pod installwith CocoaPods
Error Log#
During pod install
...
Generating Pods project
[!] An error occurred while processing the post-install hook of the Podfile.
undefined local variable or method 'config' for an instance of Pod::Podfile
*********************/ios/Podfile:66:in 'block (2 levels) in Pod::Podfile.from_ruby'
...shNotes
- The key line is:
undefined local variable or method 'config'. - The stack points to Podfile:66, inside the post-install hook.
- Likely cause:
configis out of scope inpost_install.
Root Cause#
The first line mentions that the issue was in Podfile line 66,
*********************/ios/Podfile:66:in 'block (2 levels) in Pod::Podfile.from_ruby'plaintextwhere in my case was
react_native_post_install(
installer,
config[:reactNativePath], # <-- Here
:mac_catalyst_enabled => false,
# :ccache_enabled => true
)rubyThe error undefined local variable or method 'config'... indicates that the variable reactNativePath was not found in config.
Since config is defined in target '<AppName>' block, maybe the code that referencing config[:reactNativePath] is placed outside of the target block, causing that config is out of scope, and hence CocoaPods can’t see config[:reactNativePath]
The Fix#
Move the code inside target block, or don’t reference config in post_install. Pass the RN path directly (or declare a constant at the top).
- Add this near the top:
rubyreact_native_path = File.join(__dir__, '..', 'node_modules', 'react-native') - Then change your
post_installcall to:
rubyreact_native_post_install( installer, react_native_path, # <- use the constant :mac_catalyst_enabled => false )
Summary#
This error occurs because config is defined inside the target block but referenced in post_install, where it’s out of scope. The solution is simple: define the React Native path as a constant at the top of your Podfile instead of relying on the scoped config variable.