use_native_modules! cannot locate the React Native CLI native modules helper. Fix it by ensuring @react-native-community/cli-platform-ios is installed, cleaning the yarn/npm cache, verifying react-native.config.js has valid dependencies, then running pod install --repo-update. Downgrading the CLI package to 3.0.0 can also resolve version conflicts.Why this happens
The error no implicit conversion of nil into String at the use_native_modules! line means the Ruby method received nil where it expected a path string. In a React Native project, use_native_modules! is provided by @react-native-community/cli-platform-ios and reads react-native.config.js to discover native dependencies. If the CLI package is missing, corrupted, or the config file references packages that don’t exist in node_modules, the helper returns nil and CocoaPods crashes.
Common triggers:
– The cli-platform-ios package wasn’t installed or was pruned by a cache clean.
– A version mismatch (e.g., 3.1.0 introduced a regression).
– react-native.config.js lists dependencies that aren’t actually installed.
How to fix it
1. Verify the required require_relative line
Open ios/Podfile and confirm the very first non-comment line loads the native modules helper:
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'
If the path is wrong or the file doesn’t exist, the use_native_modules! method won’t be defined.
2. Ensure the CLI platform package is installed
Check package.json for @react-native-community/cli-platform-ios. If missing, add it:
"@react-native-community/cli-platform-ios": "3.0.0"
Version 3.0.0 is known stable; newer versions (e.g., 3.1.0) have caused this exact error. Then reinstall:
yarn install
# or
npm install
3. Clean caches and reinstall
Stale caches are a frequent cause. Run:
yarn cache clean
# or
npm cache clean --force
rm -rf node_modules
rm -rf ios/Pods
rm -rf ios/Podfile.lock
yarn install
4. Validate react-native.config.js
The config file must only reference packages that exist in node_modules. A minimal valid example:
module.exports = {
project: {
ios: {},
android: {},
},
assets: ['./assets/fonts/'],
dependencies: {},
};
Remove any entries under dependencies that don’t have a corresponding folder in node_modules.
5. Reinstall CocoaPods
cd ios
pod install --repo-update
How to prevent it
- Pin
@react-native-community/cli-platform-iosto a known working version (3.0.0) inpackage.json. - Commit
yarn.lock/package-lock.jsonso CI and teammates get identical versions. - Keep
react-native.config.jsin sync with actual installed packages; run a script in CI to validate it. - Avoid manual edits to the generated parts of
Podfile; letreact-native initornpx react-native-assetmanage them.
FAQ
Why does downgrading to 3.0.0 work when 3.1.0 fails?
Version 3.1.0 changed how the native modules resolver locates packages and can return nil for valid setups. The 3.0.0 release doesn’t have that regression.
Can I fix this without modifying package.json?
If the package is already present but corrupted, yarn cache clean + rm -rf node_modules && yarn install often restores the missing file without a version change.
What if pod install still fails after these steps?
Check the full stack trace (pod install --verbose). Look for LoadError on native_modules.rb — that indicates the require_relative path is wrong for your project layout. Adjust the relative path to point to the actual node_modules location.
Parts of this guide are adapted from content licensed under CC BY-SA 4.0; this article is shared under the same license.