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!

☕️ Buy me a Coffee (€3)

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

Logging client-side errors

function logError(details) {
    type: 'POST',
    url: '',
    data: JSON.stringify({context: navigator.userAgent, details: details}),
    contentType: 'application/json; charset=utf-8'

window.onerror = function(message, file, line) {
  logError(file + ':' + line + '\n\n' + message);

Let’s keep this short. Too few websites log JavaScript errors. Let’s build a simple system to track client-side errors.

Makes clever use of the window.onerror event

Also comes with example serverside code to actually logging the event serverside

You Really Should Log Client-Side Errors →

iPhone Simulator: The simulated application quit

Fresh OS X install, fresh XCode install, and starting the iPhone Simulator (without launching any custom app) quits at start-up and spits out a “The simulated application quit” error dialog.

Turns out the Asepsis feature from TotalFinder (the feature which prevents the creation of .DS_Store files) is the culprit. Disable that feature and all will work fine.