如何放入 react-native 命令的调试器?
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升级到最新版本
- 打开模拟器应用
/Applications/Xcode.app/Contents/Developer/Applications/Simulator.app
之前react-native run-ios
要启动您的 debugger
声明,您需要:
⌘ + D
> 远程调试,打开 Google Chrome on http://localhost:8081/debugger-ui/ and 打开 JavaScript 工具⌘ + ⌥ + J
我正在做一个 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升级到最新版本
- 打开模拟器应用
/Applications/Xcode.app/Contents/Developer/Applications/Simulator.app
之前react-native run-ios
要启动您的 debugger
声明,您需要:
⌘ + D
> 远程调试,打开 Google Chrome on http://localhost:8081/debugger-ui/ and 打开 JavaScript 工具⌘ + ⌥ + J