如何在 Visual Studio Code 中为 React Native 设置调试?

Posted

技术标签:

【中文标题】如何在 Visual Studio Code 中为 React Native 设置调试?【英文标题】:How to setup debugging in Visual Studio Code for React Native? 【发布时间】:2017-05-10 00:07:30 【问题描述】:

我进行了搜索,但除了 Visual Studio Code 文档外,我找不到任何外部资源,并且仅遵循这些文档不允许在 iosandroid 中调试 React Native 应用程序。

我不断收到错误消息(Android 和 iOS 类似:

[vscode-react-native] [警告] 无法在以下位置导入脚本 http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false。 调试不起作用:尝试从应用程序内部重新加载 JS,或者 重新连接 VS Code 调试器:路径必须是字符串

我的launch.json 文件为:


    "version": "0.2.0",
    "configurations": [
        
            "name": "Debug Android",
            "program": "$workspaceRoot/.vscode/launchReactNative.js",
            "type": "reactnative",
            "request": "launch",
            "platform": "android",
            "internalDebuggerPort": 9090,
            "sourceMaps": true,
            "outDir": "$workspaceRoot/.vscode/.react"
        ,
        
            "name": "Debug iOS",
            "program": "$workspaceRoot/.vscode/launchReactNative.js",
            "type": "reactnative",
            "request": "launch",
            "platform": "ios",
            "target": "iPhone 6s",
            "internalDebuggerPort": 9090,
            "sourceMaps": true,
            "outDir": "$workspaceRoot/.vscode/.react"
        ,
        
            "name": "Attach to packager",
            "program": "$workspaceRoot/.vscode/launchReactNative.js",
            "type": "reactnative",
            "request": "attach",
            "internalDebuggerPort": 9090,
            "sourceMaps": true,
            "outDir": "$workspaceRoot/.vscode/.react"
        ,
        
            "name": "Debug in Exponent",
            "program": "$workspaceRoot/.vscode/launchReactNative.js",
            "type": "reactnative",
            "request": "launch",
            "platform": "exponent",
            "internalDebuggerPort": 9090,
            "sourceMaps": true,
            "outDir": "$workspaceRoot/.vscode/.react"
        
    ]

我正在尝试在 iOS 模拟器或 Android 设备中进行调试,但该进程从未附加到外部 JS 调试器。

【问题讨论】:

Very new to React Native - Debugging in Visual Studio Code?的可能重复 【参考方案1】:

进入vscode中的调试选项并选择调试类型

选择附加到打包程序

通过

运行您的 React Native 应用程序

    react-native run-android

-> 摇晃手机,选择Debugg remote JS 选项

完成...

【讨论】:

【参考方案2】:

您可以使用 Vscode 扩展“React native tools”来调试 react-native 应用程序。

【讨论】:

以上是关于如何在 Visual Studio Code 中为 React Native 设置调试?的主要内容,如果未能解决你的问题,请参考以下文章

如何在 Visual Studio Code 中为 Unity 函数名称获取智能感知?

如何在 Visual Code Studio 中为 pug lang 选择选项卡大小?

如何使用 anaconda3 在 Visual Studio Code 中为 python 启用智能感知?

如何在 Visual Studio Code 中为 Flutter 添加 iOS 模拟器?

如何在 WSL 的 Visual Studio Code 中为 PHP 开发设置我的 PHP 可执行路径?

Visual Studio 2017 中用于 JavaScript 和 TypeScript 文件的 Visual Studio Code 颜色主题