cli icon indicating copy to clipboard operation
cli copied to clipboard

`run-ios` wants my sudo password because it wont accept `pod` installed with bundler

Open buschco opened this issue 6 months ago • 2 comments

Environment

info Fetching system and libraries information...
System:
  OS: macOS 15.5
  CPU: (14) arm64 Apple M4 Pro
  Memory: 1.52 GB / 48.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 18.20.5
    path: ~/.nvm/versions/node/v18.20.5/bin/node
  Yarn:
    version: 1.22.22
    path: ~/.nvm/versions/node/v18.20.5/bin/yarn
  npm:
    version: 10.8.2
    path: ~/.nvm/versions/node/v18.20.5/bin/npm
  Watchman: Not Found
Managers:
  CocoaPods: Not Found
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 24.2
      - iOS 18.2
      - macOS 15.2
      - tvOS 18.2
      - visionOS 2.2
      - watchOS 11.2
  Android SDK: Not Found
IDEs:
  Android Studio: 2024.2 AI-242.23339.11.2421.12550806
  Xcode:
    version: 16.2/16C5032a
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 21.0.3
    path: /Users/colin/.sdkman/candidates/java/current/bin/javac
  Ruby:
    version: 2.7.6
    path: /Users/colin/.rbenv/shims/ruby
npmPackages:
  "@react-native-community/cli":
    installed: 18.0.0
    wanted: 18.0.0
  react:
    installed: 19.0.0
    wanted: 19.0.0
  react-native:
    installed: 0.79.2
    wanted: 0.79.2
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: false
iOS:
  hermesEnabled: true
  newArchEnabled: false

Description

I think the program fails to fast. instead it should try bundle exec pod --version first since on other places it will also respect the bundle installed version.

Reproducible Demo

  1. make sure no cocoapods is not installed globally: gem uninstall cocoapods
  2. npx @react-native-community/cli@latest init MyApp
  3. press n for cocoa pods question
  4. cd MyApp
  5. bundle install

Now bundle exec pod --version has an 0 exit code.

npx react-native run-ios --force-pods will either fail or globally install cocoapods again, but it does not need to since we can use bundle exec pod instead.

buschco avatar Jun 03 '25 12:06 buschco

I submitted an PR (https://github.com/react-native-community/cli/pull/2669) that should fix this issue by using the right pod command

buschco avatar Jun 03 '25 13:06 buschco

If you only want to use the pod installed with bundler you can use this patch:

patches/@react-native-community+cli-config-apple+18.0.0.patch

diff --git a/node_modules/@react-native-community/cli-config-apple/build/tools/installPods.js b/node_modules/@react-native-community/cli-config-apple/build/tools/installPods.js
index fc52a47..217d71b 100644
--- a/node_modules/@react-native-community/cli-config-apple/build/tools/installPods.js
+++ b/node_modules/@react-native-community/cli-config-apple/build/tools/installPods.js
@@ -75,7 +75,7 @@ async function runPodInstall(loader, options) {
 async function runPodUpdate(loader) {
   try {
     loader.start(`Updating CocoaPods repositories ${_chalk().default.dim('(this may take a few minutes)')}`);
-    await (0, _execa().default)('pod', ['repo', 'update']);
+    await (0, _execa().default)('bundle', ['exec', 'pod', 'repo', 'update']);
   } catch (error) {
     // "pod" command outputs errors to stdout (at least some of them)
     _cliTools().logger.log(error.stderr || error.stdout);
@@ -125,7 +125,7 @@ async function installPods(loader, options) {
       // Check if "pod" is available and usable. It happens that there are
       // multiple versions of "pod" command and even though it's there, it exits
       // with a failure
-      await (0, _execa().default)('pod', ['--version']);
+      await (0, _execa().default)('bundle', ['exec', 'pod', '--version']);
     } catch (e) {
       loader.info();
       await installCocoaPods(loader);

buschco avatar Jun 03 '25 13:06 buschco