react-native run-ios can not find any simulator

后端 未结 8 644
滥情空心
滥情空心 2020-12-03 08:07

I have been facing an issue where \'react-native run-ios\' can not start, regardless of the simulator I add to the --simulator argument. XCode has the correct location for t

相关标签:
8条回答
  • 2020-12-03 08:53

    Here is additional temporary fix too. I am using Catalina.

    I this file:

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

    Change line 42 to:

    if (!version.includes('iOS') && !version.includes('tvOS')) {
    

    Change line 52-53 from:

    simulator.availability !== '(available)' &&
    simulator.isAvailable !== 'YES'
    

    to:

    simulator.isAvailable !== true
    

    because the returned json list from command xcrun simctl list --json devices, the property isAvailable is boolean and didn't have property 'availability'.

    0 讨论(0)
  • 2020-12-03 08:54

    Just modify the findMatchingSimulator.js in node_modules/react-native/local-cli/runIOS/findMatchingSimulator.js.

    First boot a Simulator then run xcrun simctl list --json devices and search the one with "state" : "Booted",.

    Then add at the top in the findMatchingSimulator function:

    return {
    udid: <uuid from booted device>, // 'BFA2D7D0-AD49-472F-8279-585DDBBF9151'
    name: <Name of the booted simulator>, //"iPhone X"
    booted: true,
    version: "com.apple.CoreSimulator.SimRuntime.iOS-13-1",
    

    }

    0 讨论(0)
  • 2020-12-03 08:59

    I solved it by replacing line number 62 in YourProjectFolder/node_modules/react-native/local-cli/runIOS/findMatchingSimulator.js

    This line

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

    With this one

    if (
          !simulator.isAvailable
       ) {
    

    In some case there may be some different solutions for everyone just debug findMatchingSimulator.js file by putting console.log() so you'll know why it is not detecting simulator. In my case the xcrun simctl list devices --json command not providing simulator.availability and simulator.isAvailable is not string it's bool. I printed the simulator list which command is returning through the following line

      console.log(JSON.stringify(simulator.simulatorName));
      console.log(simulator.isAvailable);
      console.log('-------------------------------------------------------------');
    

    The after running command react-native run-ios --simulator="iPhone SE" I got output in the terminal and fixed code according to console print. And my simulator was running.

    0 讨论(0)
  • 2020-12-03 09:00

    Just do

    npm install

    Then it will show warnings, then fix them by using following command

    npm audit fix

    0 讨论(0)
  • 2020-12-03 09:02

    I tried like below

    Open Xcode. Then Preferences -> Select Components in Tabs.

    Then install any one(or more) of the available simulators on the list. Preferably the recent one at the top.

    It solves the problem.

    0 讨论(0)
  • 2020-12-03 09:09

    Try this script from Terminal

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

    Now run

    react-native run-ios
    
    0 讨论(0)
提交回复
热议问题