cli: error Could not find iPhone X simulator

Environment

info
  React Native Environment Info:
    System:
      OS: macOS 10.14.5
      CPU: (8) x64 Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
      Memory: 8.56 GB / 16.00 GB
      Shell: 5.3 - /bin/zsh
    Binaries:
      Node: 11.14.0 - /usr/local/bin/node
      Yarn: 1.15.2 - /usr/local/bin/yarn
      npm: 6.9.0 - /usr/local/bin/npm
      Watchman: 4.9.0 - /usr/local/bin/watchman
    SDKs:
      iOS SDK:
        Platforms: iOS 12.2, macOS 10.14, tvOS 12.2, watchOS 5.2
      Android SDK:
        API Levels: 23, 25, 26, 27, 28
        Build Tools: 23.0.1, 25.0.0, 26.0.3, 27.0.3, 28.0.2, 28.0.3
        System Images: android-23 | Intel x86 Atom_64, android-23 | Google APIs Intel x86 Atom_64, android-28 | Google APIs Intel x86 Atom
    IDEs:
      Android Studio: 3.2 AI-181.5540.7.32.5056338
      Xcode: 10.2.1/10E1001 - /usr/bin/xcodebuild
    npmPackages:
      react: 16.8.3 => 16.8.3
      react-native: 0.59.9 => 0.59.9
    npmGlobalPackages:
      create-react-native-app: 1.0.0
      create-react-native-web-app: 0.1.11
      react-native-cli: 2.0.1
      react-native-git-upgrade: 0.2.7

Description

Not related to https://github.com/facebook/react-native/issues/21824 https://github.com/facebook/react-native/issues/23282 as they have older versions of react-native. 59.9 doesn’t even have the files they mentions because this repo now handles it.

Since 59.9 and upgrading to xcode 10.2 react-native run-ios always produces an error. I’ve tried reinstalling simulators and even xcode itself many times now. I’ve also heard frojm many people that updgrading to xcode 10.2 produces this error as well.

Reproducible Demo

A good repro is completely uninstalling xcode then reinstalling it, start a new project, then you should get the error.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 53 (15 by maintainers)

Most upvoted comments

error Could not find "iPhone X" simulator. Run CLI with --verbose flag for more details.

Problem

There is no iPhone X!

Run Simulator by itself, in the top menu, look under Hardware, Device, iOS 13.0.

You will see there is:

  • iPhone 8
  • iPhone 8 Plus
  • iPhone XS
  • iPhone XS Max
  • iPhone XR
  • … and some iPads

When you execute run-ios, react-native is designed to match a requested device.

The internally hard coded default is iPhone X.

The function that tries to match the requested device is in:

/node_modules/@react-native-community/cli-platform-ios/build/commands/runIOS/findMatchingSimulator.js

This function is designed so you can give it a device, and an optional version number.

If the given device and version cannot be found, it will return a match using the first device in the list by default.

But… in reality, the first device is a watch, and any watch is excluded from matching, so this function will return null.

Solution

Run Simulator first by itself, as described above, and make a note of which iPhone or iPad you want.

Then pass this name as an optional argument the the run-ios command line command as follows:

react-native run-ios --simulator="iPhone 8"

Also answered here: react-native run-ios returns Error: Could not find iPhone X simulator

I tried the above and nothing seemed to work. The following command worked for me. sudo killall -9 com.apple.CoreSimulator.CoreSimulatorService

Hi All,

I found other solution without changing any source code in node_modules directory.

  1. Create react-native project folder (command: react-native init projectName)
  2. Open file projectName/ios/projectName.xcworkspace file in Xcode 11
  3. Choose device that you want to use (iPhone X not in list anymore after releasing iPhone Pro, so you need click on plus button and add to current list of devices)
  4. When your new device in list you can close Xcode 11 and try to run emulator from Terminal (react-native run-ios)

if you need any screenshots how to do that just let me know.

This is my first comment in github by the way so congrats me 😃

Thank you.

Adding an iPhone X simulator through the command-line solved the issue for me, as I couldn’t find an iPhone X simulator to install in the GUI on Xcode 11. Here is the command-line code:

/Applications/Xcode.app/Contents/Developer/usr/bin/simctl create "iPhone X" com.apple.CoreSimulator.SimDeviceType.iPhone-X com.apple.CoreSimulator.SimRuntime.iOS-13-0

This fixed the error for me.

  • Open Xcode.
  • Select Window > Devices and Simulators from the top menu bar.
  • In the Devices and Simulators window, select the Simulators tab.
  • Add the iPhone X (and any others) in the left sidebar.
  • Don’t give it a custom name since RN is looking for iPhone X.
  • Click Create.

Also, make sure you have the latest CLI (so remove @react-native-community/cli from lockfile and run install again)

@carloshuerta I added iPhone X manually in Xcode but still it is not working.

Apparently iPhone X is not available on the iOS 13.0 simulators, but you can easily add it by going to xcode and add it manually, once you add it there, run the “react-native run-ios” command again and it works.

Tried @nickcurran’s approach, didn’t work. Rebooted, didn’t work.

I installed XCode 11 beta 5, which is when the problem started.

With 0.61 and Xcode 11, my fix is just adding a script in package.json in the scripts object:

"ios": "react-native run-ios --simulator 'iPhone 11 Pro'",

So you can run npm run ios.

But the real solution is to stop hardcoding in React Native Cli and always use whatever was the last used simulator from Xcode.

react-native : 0.57.8 i solved the problem

  1. change the file node_modules/react-native/local-cli/runIOS/findMatchingSimulator.js 42 line as below
    if (
      !version.startsWith('com.apple.CoreSimulator.SimRuntime.iOS') &&
      !version.startsWith('com.apple.CoreSimulator.SimRuntime.tvOS')
    ) {
      continue;
    }
  1. change the file node_modules/react-native/local-cli/runIOS/findMatchingSimulator.js 56 line as below
      if (!simulator.isAvailable) {
        continue;
      }

Rebooting did not solve this for me. Turns out that the Xcode Beta was set as the current command line version of code. Running

sudo xcode-select -s /Applications/Xcode.app/Contents/Developer

fixed it for me.

A reboot does seem to have fixed it. I encountered the issue as I was trying to do one last build before signing off yesterday, or I probably would have rebooted myself. Either way, it appears a reboot is necessary, and then it is fixed.

Another repro could be to download the new xcode beta. I regret doing it now but that could be the root cause

Oh, that’s weird, because your envinfo shows Xcode: 10.2.1/10E1001 - /usr/bin/xcodebuild.

Then you may hit this: https://github.com/react-native-community/cli/pull/414 (will make a release soon)

quick hack without upgrading react native change the file node_modules/react-native/local-cli/runIOS/findMatchingSimulator.js as below

image

@methuz react-native 0.61 was released earlier today so it’s downgrading if you’re starting today with .60

I solved by upgrading to react-native 0.60

react-native version “<60.0.0” which resolve “@react-native-community/cli” => “^1.0.0” is not compatible to Xcode 11.

Xcode simulator list format is not compatible to “@react-native-community/cli@^1.0.0”

1 solution is using “resolutions” in package.json,

  "resolutions": {
    "@react-native-community/cli": "^2.8.3"
  },

Or, patch every time for ./node_modules/@react-native-community/cli/build/commands/runIOS/findMatchingSimulator.js using “postinstall” or something else.

Debugged a bit into this. I think the CLI does everything correctly, xcode is reporting the simulator as unavailable, see xcrun simctl list devices. But a simple reboot fixes it…

@thymikee Thanks for the quick response though!

Released 1.9.8 with the fix

Can you try if applying that diff in your node_modules helps?