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?
Consider donating.

I don’t run ads on my blog nor do I do this for profit. A donation however would always put a smile on my face though. Thanks!

☕️ Buy me a Coffee ($3)

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.