15

I upgraded to Xcode 10.2 today, since upgrading I can't run react-native run-ios through the cli:

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

Found Xcode workspace a.xcworkspace

Could not find iPhone X simulator

Error: Could not find iPhone X simulator
    at resolve (/Users/user/Documents/work/a/a-light-ui/node_modules/react-native/local-cli/runIOS/runIOS.js:149:13)
    at new Promise (<anonymous>)
    at runOnSimulator (/Users/user/Documents/work/a/a-light-ui/node_modules/react-native/local-cli/runIOS/runIOS.js:134:10)
    at Object.runIOS [as func] (/Users/user/Documents/work/a/a-light-ui/node_modules/react-native/local-cli/runIOS/runIOS.js:106:12)
    at Promise.resolve.then (/Users/user/Documents/work/a/a-light-ui/node_modules/react-native/local-cli/cliEntry.js:117:22)    

If I run xcrun simctl list devices all of the simulators show (Shutdown) (unavailable, runtime profile not found):

iPhone X (7AADFA50-7B57-4A40-8434-9A86F345D7ED) (Shutdown) (unavailable, runtime profile not found)

Has anyone else had this issue with RN since upgrading xcode to 10.2? It still works through Xcode.. but that means opening Xcode.

Paul R
  • 208,748
  • 37
  • 389
  • 560
smj2393
  • 1,929
  • 1
  • 23
  • 50

5 Answers5

23

I solved like this ;

Firstly, you need to go this path

node_modules/react-native/local-cli/runIOS/findMatchingSimulator.js

and then;

You need to change this code

if (!version.startsWith('iOS') && !version.startsWith('tvOS'))

with

if (!version.startsWith('com.apple.CoreSimulator.SimRuntime.iOS') && !version.startsWith('com.apple.CoreSimulator.SimRuntime.tvOS'))

I hope, it will be helpful,

ref : https://github.com/facebook/react-native/issues/21498#issuecomment-476621627

krnz
  • 246
  • 2
  • 3
  • This works! Thanks @Abdullah K. Hopefully they release a proper fix soon as this means we will need to make this change every-time we run `npm install` – smj2393 Mar 27 '19 at 10:46
  • It is working. Also found the solution here: https://github.com/facebook/react-native/issues/23282 – ljmocic Apr 03 '19 at 09:07
1

I thought I would add my solution here too, in hopes to help someone. I just upgraded to Mac OS Mojave and I also upgraded to Xcode 10.2. My whole react native project broke, real bad. So then I downgraded Xcode back to 10.1. Then, I started to see this error, in said after running react-native run-ios:

Could not find iPhone X simulator

the above "hack" fixed it by editing the findMatchingSimulator.js file with the updates above.

Then, react-native run-ios got farther, next error was:

:CFBundleIdentifier, does not exist

I fixed this by:

  1. cd node_modules/react-native/third-party/glog* TabEnter
  2. ./configure

Now react-native run-ios works . I hope this helps someone, this was a pain in the @ss.

oguz ismail
  • 1
  • 16
  • 47
  • 69
shinercoder
  • 31
  • 1
  • 1
  • 4
0

This bug has been fixed since RN v0.58.0, see commits here

IIRC this bug was introduced in Xcode 10.1

Also, you can fix this by simply replacing startsWith() with includes(). But doing this every time you update node_modules is less than ideal so I would recommend updating your RN version if possible.

Evan Butler
  • 51
  • 1
  • 4
0

if could not found simulator still persists after replacing following lines of code in runSimulator.js.

Path for runSimulator.js -> /node_modules/react-native/local-cli/runIOS/findMatchingSimulator.js

if (!version.startsWith('iOS') && !version.startsWith('tvOS')) { continue; }

with this one

if ( !version.startsWith('com.apple.CoreSimulator.SimRuntime.iOS') && !version.startsWith('com.apple.CoreSimulator.SimRuntime.tvOS') ) { continue; }

comment following lines after replacing

if ( simulator.availability !== '(available)' && simulator.isAvailable !== 'YES' ) { continue; }

and 2nd approach after updating to XCode 11

Xcode 11 xcrun returns true or false and not YES or NO for isAvailable property as before. You can check that using the following command

xcrun simctl list devices --json 

above command will print all available devices like following

 com.apple.CoreSimulator.SimRuntime.iOS-12-2" : [
  {
    "state" : "Booted",
    "isAvailable" : true,
    "name" : "iPhone X",
    "udid" : "E53748D1-628B-4A99-A419-4D7AE7CE4745"
  }
]

Replace YES with true in the following code

if ( simulator.availability !== '(available)' && simulator.isAvailable !== 'YES' ) { continue; }

like this

if ( simulator.availability !== '(available)' && simulator.isAvailable !== true ) { continue; }
kaushal
  • 903
  • 10
  • 17
-1

You even just do something like this

if (version.indexOf('iOS') === -1)...

Tausif
  • 1