React-Native “Could not find iPhone X simulator”

One of my React Native projects recently decided to no longer launch any of the iPhone Simulator devices anymore. When running react-native run-ios I was greeted with an error stating that the simulator could not be found.

bramus in ~/repos/projects/react-native-maps-directions-example on master*
$ react-native run-ios --simulator="iPhone X"
Found Xcode project RNMapsExample.xcodeproj

Could not find iPhone X simulator

Error: Could not find iPhone X simulator
    at Promise.then.udid.udid (/Users/bramus/repos/projects/react-native-maps-directions-example/node_modules/react-native/local-cli/runIOS/runIOS.js:149:13)
    at new Promise (<anonymous>)
    at runOnSimulator (/Users/bramus/repos/projects/react-native-maps-directions-example/node_modules/react-native/local-cli/runIOS/runIOS.js:134:10)
    at Object.runIOS [as func] (/Users/bramus/repos/projects/react-native-maps-directions-example/node_modules/react-native/local-cli/runIOS/runIOS.js:106:12)
    at /Users/bramus/repos/projects/react-native-maps-directions-example/node_modules/react-native/local-cli/cliEntry.js:117:22

error Command failed with exit code 1.

No matter which simulator I targeted, the error always remained …

💁‍♂️ To list all available simulators, which you can pass into –simulator, run this command:

$ xcrun simctl list

The cause

The issue occurs for older RN versions (0.57, 0.58 (<0.58.4), …) with Xcode 10.3, where the names of the available simulators got somewhat tweaked. In the file node_modules/@react-native-community/cli/build/commands/runIOS/findMatchingSimulator.js, React Native tries to select the proper Simulator with a simple .startsWith check. Due to the rename, the check should now use .includes (ref).

The fix

React 0.58.4 and up do not have this problem. If you can upgrade to React Native 0.58.4 or newer, then do.

If you cannot or wont upgrade to a newer RN version, then you can automate the adjustment in the findMatchingSimulator.js file with this command:

sed -i '' 's/startsWith/includes/g' node_modules/react-native/local-cli/runIOS/findMatchingSimulator.js

Put it in a postinstall script in your package.json and your colleagues/CI will also automaticlaly pick it up:

"scripts": {
    "postinstall": "sed -i '' 's/startsWith/includes/g' node_modules/react-native/local-cli/runIOS/findMatchingSimulator.js"
}

The postinstall script will be run right after yarn install did its thing, ensuring the fix is applied 🙂

Did this help you out? Like what you see?
Thank me with a coffee.

I don\'t do this for profit but a small one-time donation would surely put a smile on my face. Thanks!

BuymeaCoffee (€3)

To stay in the loop you can follow @bramus or follow @bramusblog on Twitter.

Published by Bramus!

Bramus is a frontend web developer from Belgium, working as a Chrome Developer Relations Engineer at Google. From the moment he discovered view-source at the age of 14 (way back in 1997), he fell in love with the web and has been tinkering with it ever since (more …)

Unless noted otherwise, the contents of this post are licensed under the Creative Commons Attribution 4.0 License and code samples are licensed under the MIT License

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.