cli: react-native run-ios --device not working with XCode 12.5 CLI tools

Environment

System:
    OS: macOS 11.3
    CPU: (8) x64 Intel(R) Core(TM) i5-8259U CPU @ 2.30GHz
    Memory: 626.05 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 14.2.0 - /var/folders/34/_v0h6lqn0x17yx6pppvqrnbmcjbc20/T/yarn--1619714124765-0.3284344217580091/node
    Yarn: 1.22.10 - /var/folders/34/_v0h6lqn0x17yx6pppvqrnbmcjbc20/T/yarn--1619714124765-0.3284344217580091/yarn
    npm: 6.14.4 - ~/.nvm/versions/node/v14.2.0/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  Managers:
    CocoaPods: 1.10.1 - /usr/local/bin/pod
  SDKs:
    iOS SDK:
      Platforms: iOS 14.5, DriverKit 20.4, macOS 11.3, tvOS 14.5, watchOS 7.4
    Android SDK:
      API Levels: 23, 28, 29
      Build Tools: 28.0.3, 29.0.2, 29.0.3
      System Images: android-28 | Intel x86 Atom_64, android-29 | Google APIs Intel x86 Atom, android-30 | Google Play Intel x86 Atom
      Android NDK: Not Found
  IDEs:
    Android Studio: 4.1 AI-201.8743.12.41.7042882
    Xcode: 12.5/12E262 - /usr/bin/xcodebuild
  Languages:
    Java: 1.8.0_252 - /usr/bin/javac
  npmPackages:
    @react-native-community/cli: Not Found
    react: 17.0.1 => 17.0.1 
    react-native: 0.64.0 => 0.64.0 
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

Description

After upgrading to the latest version of Xcode (12.5), I can no longer run my react-native project on a physical device. Running react-native run-ios --device=X always results in an error and a message that there are no available devices to run on:

image

I’ve tracked the issue down to this line. It seems that xcrun xctrace list devices no longer outputs to stderr:

image

tail error => empty, tail out => list of devices. Changing the above line to stdout instead of stderr fixes the issue locally for me.

Reproducible Demo

This should be reproducible on any react-native project when running XCode 12.5, but if I’m mistaken, let me know and I’ll try to put together a minimal demo.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 16
  • Comments: 17 (2 by maintainers)

Most upvoted comments

I ran into the same issue, and found the same solution as you. Temporarily fixing with the following patch-package patch: @react-native-community+cli-platform-ios+5.0.1-alpha.2.patch

diff --git a/node_modules/@react-native-community/cli-platform-ios/build/commands/runIOS/index.js b/node_modules/@react-native-community/cli-platform-ios/build/commands/runIOS/index.js
index ac4cd9f..ce330d8 100644
--- a/node_modules/@react-native-community/cli-platform-ios/build/commands/runIOS/index.js
+++ b/node_modules/@react-native-community/cli-platform-ios/build/commands/runIOS/index.js
@@ -128,7 +128,7 @@ function runIOS(_, ctx, args) {
   let devices;
 
   try {
-    devices = (0, _parseXctraceIOSDevicesList.default)(_execa().default.sync('xcrun', ['xctrace', 'list', 'devices']).stderr);
+    devices = (0, _parseXctraceIOSDevicesList.default)(_execa().default.sync('xcrun', ['xctrace', 'list', 'devices']).stdout);
   } catch (e) {
     _cliTools().logger.warn('Support for Xcode 11 and older is deprecated. Please upgrade to Xcode 12.');
 

I ran into the same issue, and found the same solution as you. Temporarily fixing with the following patch-package patch: @react-native-community+cli-platform-ios+5.0.1-alpha.2.patch

diff --git a/node_modules/@react-native-community/cli-platform-ios/build/commands/runIOS/index.js b/node_modules/@react-native-community/cli-platform-ios/build/commands/runIOS/index.js
index ac4cd9f..ce330d8 100644
--- a/node_modules/@react-native-community/cli-platform-ios/build/commands/runIOS/index.js
+++ b/node_modules/@react-native-community/cli-platform-ios/build/commands/runIOS/index.js
@@ -128,7 +128,7 @@ function runIOS(_, ctx, args) {
   let devices;
 
   try {
-    devices = (0, _parseXctraceIOSDevicesList.default)(_execa().default.sync('xcrun', ['xctrace', 'list', 'devices']).stderr);
+    devices = (0, _parseXctraceIOSDevicesList.default)(_execa().default.sync('xcrun', ['xctrace', 'list', 'devices']).stdout);
   } catch (e) {
     _cliTools().logger.warn('Support for Xcode 11 and older is deprecated. Please upgrade to Xcode 12.');
 

For others waiting for this fix in a new release of the cli, apply the above patch by placing it in a file called @react-native-community+cli-platform-ios+5.0.1-alpha.2.patch in your project folder, and running:

patch -p1 < @react-native-community+cli-platform-ios+5.0.1-alpha.2.patch

I submitted a pull request for this. Ran into this issue after updating to Xcode 12.5.

After upgrading to the latest version of Xcode 13.2.1 was hitting “error No iOS devices connected.” as well after running react-native run-ios --device. Tried to upgrade my react-native version from 0.62 to 0.64.2 (removed instruments error) and still doesn’t work.

In the end it’s due to my iPhone (iOS 15.2.1) name is having brackets! (e.g. iPhone (2)). These brackets were added automatically to the iPhone name after migrating from old iphone to new iphone.

So if everything doesn’t work for you just remove the brackets from the iPhone name!

Hello, 6.0.0-rc.0 was not working for me 😉

5.0.1-alpha.2 was published before PR #1407 was merged.

I recommend you consider trying the 6.0.0-rc.0 or @react-native-community/cli@next version from npm which should include the bugfix.