在 Visual Studio Code 中调试?

标签 debugging react-native visual-studio-code

我按照 VSCode 中的调试说明进行操作

https://github.com/Microsoft/vscode-react-native

我将带有 USB 线的 Nexus 6P 与 MBP2015 连接起来,并启用了开发者选项和 USB 调试,但是当我在 VSC 中选择“调试 Android”时,我得到了此信息

[Error] "Could not debug. Android project not found."

我也附上了这张照片。

如果我想在 IOS 模拟器上进行调试,我在 VSC 中选择“调试 IOS”,但随后我得到了此消息,并且模拟器未启动

[vscode-react-native] Prewarming bundle cache. This may take a while ...
[vscode-react-native] Building and running application.
[vscode-react-native] Executing command: react-native run-ios --simulator
Scanning 772 folders for symlinks in /Users/me/reactnativework/my-app/node_modules (4ms)
ENOENT: no such file or directory, uv_chdir
[Error] "Could not debug. Error while executing command 'react-native run-ios --simulator': Error while executing command 'react-native run-ios --simulator'"

我在这里看到了一些关于类似问题的帖子,但没有一个得到解答,或者与我遇到的问题不同。

如何使用断点调试最简单的 React Native 应用程序,以便我可以跟踪代码在 Visual Studio Code 中的执行方式?

这是我的 launch.json

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Debug Android",
            "program": "${workspaceRoot}/.vscode/launchReactNative.js",
            "type": "reactnative",
            "request": "launch",
            "platform": "android",
            "sourceMaps": true,
            "outDir": "${workspaceRoot}/.vscode/.react"
        },
        {
            "name": "Debug iOS",
            "program": "${workspaceRoot}/.vscode/launchReactNative.js",
            "type": "reactnative",
            "request": "launch",
            "platform": "ios",
            "sourceMaps": true,
            "outDir": "${workspaceRoot}/.vscode/.react"
        },
        {
            "name": "Attach to packager",
            "program": "${workspaceRoot}/.vscode/launchReactNative.js",
            "type": "reactnative",
            "request": "attach",
            "sourceMaps": true,
            "outDir": "${workspaceRoot}/.vscode/.react"
        },
        {
            "name": "Debug in Exponent",
            "program": "${workspaceRoot}/.vscode/launchReactNative.js",
            "type": "reactnative",
            "request": "launch",
            "platform": "exponent",
            "sourceMaps": true,
            "outDir": "${workspaceRoot}/.vscode/.react"
        }
    ]
}

最佳答案

按照以下步骤操作

  • 安装扩展React-native完整包

enter image description here

  • 创建Launch.json

enter image description here

  • 选择调试 iOSAndroid。添加断点并享受。

enter image description here

注意:请确保启用远程调试 JS

enter image description here

现在喝杯咖啡享受吧!

关于在 Visual Studio Code 中调试?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46654585/

相关文章:

c - 在 MakeFile 中使用调试器

java - 添加 Java 异常断点在 Eclipse 中不显示任何匹配项

reactjs - 将本地镜像路径作为两个功能组件之间的 prop 传递

debugging - 如何知道 Spring 生成的 bean 中的 bug 所在行?

javascript - 脚本调试不起作用 (VS 2008)

javascript - React Native 中全局对象的模式

react-native - React Native Flatlist keyExtractor 说明

Git push : Missing or invalid credentials.致命: 'https://github.com/username/repo.git'身份验证失败

java - 如何在VSCODE中运行两个Java文件?

visual-studio-code - TextMate 语法和主题如何与 VSCode 配合使用?