【问题标题】:vscode nodejs remote debug RPivscode nodejs 远程调试 RPi
【发布时间】:2020-10-24 01:30:54
【问题描述】:

我正在尝试设置 VScode 以在 Raspberry Pi 4 上调试远程 nodejs 应用程序。我使用 VScode - Insiders 和 Remote Development 扩展与 Remote - SSH(每晚)。 SSH 连接工作得非常好,我可以轻松调试远程 Python 程序。当我启动 nodejs 程序(test.js)时,什么也没有发生。在调试控制台中,我只看到:/usr/bin/node test.js,然后什么也没有发生。我可以在 VScode 终端中执行同一行并按预期运行。 我的启动配置如下,远程节点调试可用。 有人可以帮帮我吗?

    {
        "name": "Launch Program",
        "program": "${workspaceFolder}/test.js",
        "request": "launch",
        "skipFiles": [
            "<node_internals>/**"
        ],
        "type": "node"
    },

【问题讨论】:

  • 我也在打这个。根据我对 vscode 远程 ssh 扩展的阅读,这应该可以正常工作,您不必手动设置检查器和端口。

标签: node.js visual-studio-code vscode-remote


【解决方案1】:

在以下示例中,您的项目将驻留在您的服务器上的 /path/to/my/project 中,并且您的应用程序将被称为 index.js。

在服务器上

导航到您的项目:

cd /path/to/my/project/

运行您的应用程序,通过将--inspect 参数设置为您将从本地系统隧道进入的端口来激活检查器:

node --inspect=0.0.0.0:9229 ./index.js

在本地开发系统上

设置到您的服务器的 SSH 隧道(将 username@remote.com 替换为您的用户名和服务器地址):

ssh -L 9221:localhost:9229 username@remote.com

服务器的 9229 端口现在映射到您的 localhost 的 9221 端口。

在 VS Code 中添加如下配置:

{
    "type": "node",
    "request": "attach",
    "name": "Debug remote",
    "protocol": "inspector",
    "address": "localhost",
    "port": 9221,
    "sourceMaps": true,
    "localRoot": "${workspaceFolder}",
    "remoteRoot": "/path/to/my/project/"
}

在代码中设置断点并在 VS Code 中启动“远程调试”配置。

当您在浏览器中加载请求时,代码现在将在断点处停止。

【讨论】:

    猜你喜欢
    • 2019-03-28
    • 2018-07-11
    • 1970-01-01
    • 2019-07-01
    • 2016-07-01
    • 2021-08-10
    • 1970-01-01
    • 1970-01-01
    • 2019-07-13
    相关资源
    最近更新 更多