簡體   English   中英

如何放入調試器以進行本機命令?

[英]How to drop into the debugger for a react-native command?

我正在開發一個React Native項目,如果嘗試運行react-native run-ios會遇到以下錯誤,但出現錯誤Could not find iPhone 6 simulator

> react-native run-ios
Scanning folders for symlinks in /Users/kurtpeek/mobile/applicant-app/node_modules (16ms)
Found Xcode workspace applicant.xcworkspace

Could not find iPhone 6 simulator

但是,如果我運行xcrun simctl list --json devices ,此模擬器確實會顯示,類似於在node_modules/react-native/local-cli/runIOS/runIOS.js

> xcrun simctl list --json devices | grep "\"iPhone 6\"" -B 5 -A 5
      },
      {
        "availability" : "(available)",
        "state" : "Shutdown",
        "isAvailable" : true,
        "name" : "iPhone 6",
        "udid" : "93E4D0AF-C267-406B-B8F5-B3B305BEBBF0",
        "availabilityError" : ""
      },
      {
        "availability" : "(available)",

上述文件中的runOnSimulator函數讀取

function runOnSimulator(xcodeProject, args, scheme) {
  return new Promise((resolve) => {
    try {
      var simulators = JSON.parse(
      child_process.execFileSync('xcrun', ['simctl', 'list', '--json', 'devices'], {encoding: 'utf8'})
      );
    } catch (e) {
      throw new Error('Could not parse the simulator list output');
    }

    const selectedSimulator = findMatchingSimulator(simulators, args.simulator);
    if (!selectedSimulator) {
      throw new Error(`Could not find ${args.simulator} simulator`);
    }

因此,我想在node_modules/react-native/local-cli/runIOS/findMatchingSimulator.js設置調試器斷點。 我試過簡單地在其中放入debugger語句,如下所示:

function findMatchingSimulator(simulators, simulatorName) {
  debugger;

  if (!simulators.devices) {
    return null;
  }

但這不會啟動調試器(例如,在Python中設置import pdb; pdb.set_trace() )。 如何調試react-native CLI命令?

您有2個選擇:

  • 將您的macOS系統 Xcode升級到最新版本
  • react-native run-ios 之前打開模擬器應用程序/Applications/Xcode.app/Contents/Developer/Applications/Simulator.app

要啟動debugger語句,您需要:

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM