简体   繁体   English

VSC 调试器不会附加到 RPi 上的 node.js

[英]VSC Debugger does not attach to node.js on RPi

I'm trying to set up VSC on a Macbook to remote debug nodejs on a Raspberry Pi.我正在尝试在 Macbook 上设置 VSC 以在 Raspberry Pi 上远程调试 nodejs。 Node is running with Inspector ( --inspect-brk ) on the Pi and there seems to be some connection, but neither the .js file is opened nor is the editor jumping to the first line. Node 在 Pi 上与 Inspector ( --inspect-brk ) 一起运行,似乎有一些连接,但 .js 文件既没有打开,编辑器也没有跳到第一行。 I followed this instruction: https://github.com/BretStateham/pinodevscode I googled 3 evenings already without success.我按照以下说明进行操作: https : //github.com/BretStateham/pinodevscode我用谷歌搜索了 3 个晚上都没有成功。 For checking, if remote debugging generally works, I have set up a remote debugging configuration that attaches to nodejs on my Macbook (this works like a charm).为了检查,如果远程调试通常有效,我已经设置了一个远程调试配置,该配置附加到我的 Macbook 上的 nodejs(这就像一个魅力)。 When I try to do exactly the same thing with the RPi (so I basically put a different IP address and RemoteRoot in the config) it does no longer work.当我尝试对 RPi 做完全相同的事情时(所以我基​​本上在配置中放置了不同的 IP 地址和 RemoteRoot),它不再起作用。

Here's what I did so far in the Pi setup:这是我目前在 Pi 设置中所做的:

  • followed the instructions in https://github.com/BretStateham/pinodevscode按照https://github.com/BretStateham/pinodevscode 中的说明进行操作
  • My samba Share is called DEV, mapped to /home/user, my code resides in the subfolder MYCODE我的samba Share叫DEV,映射到/home/user,我的代码在子文件夹MYCODE
  • I can run my script via SSH on the terminal of the RPi我可以在 RPi 的终端上通过 SSH 运行我的脚本
  • I tried first with the default port 9229, moved to other ports later, follwing a recommendation on a similar post somewhere, but no success我首先尝试使用默认端口 9229,稍后移至其他端口,遵循某处类似帖子的建议,但没有成功
  • I can start node -inspect-brk:192.168.178.42:9229 app.js , it reports that inspector is listening on the port and I can see the port open, when I scan from the Mac我可以启动node -inspect-brk:192.168.178.42:9229 app.js ,它报告检查器正在侦听端口,当我从 Mac 扫描时,我可以看到端口打开
  • I have setup a launch configuration based on the template in VSC (see below)我已经根据 VSC 中的模板设置了启动配置(见下文)
  • When I run the configuration, the status bar turns orange, indicating a connection, but the .js file is not opened (as it is in the configuation attaching to the local script) and nothing happens (also the button attached to the Pi GPIO is not doing anything, so the script seems to be waiting for the debugger to attach)当我运行配置时,状态栏变为橙色,表示连接,但 .js 文件没有打开(因为它在附加到本地脚本的配置中)并且没有任何反应(连接到 Pi GPIO 的按钮也是什么都不做,所以脚本似乎在等待调试器附加)
  • The Debugger Buttons (Step Over, Step into, Step out) stay grayed out调试器按钮(Step Over、Step into、Step out)保持灰色
  • I was thinking, that something might be wrong with the synchronization of the root paths (that sometimes was tricky, when I used Eclipse in the past), but I checked it several times: both the local path to the files on the Pi via mounted Samba share and the remote path to the files on the Pi point to the same files.我在想,根路径的同步可能有问题(这有时很棘手,当我过去使用 Eclipse 时),但我检查了几次:Pi 上文件的本地路径都通过安装Samba 共享和 Pi 上文件的远程路径指向相同的文件。
  • I have turned on "trace" in the configuration.我在配置中打开了“跟踪”。 The log shows a successfull connection to the remote system and I cannot really figure out, what goes wrong日志显示成功连接到远程系统,但我真的不知道出了什么问题
  • I did a diff between the logfile of the local (working) setup and the logfile of the remote (failing) setup (see below).我在本地(工作)设置的日志文件和远程(失败)设置的日志文件之间做了一个差异(见下文)。 Beside paths, IPs, session ID and timestamps there are only few differences before the actual debugging communication starts in the local setup除了路径、IP、会话 ID 和时间戳之外,在本地设置中实际调试通信开始之前只有很少的区别
  • I tried to use the SSH tunnel from local to remote system instead of exposing the inspector port on the RPi (as proposed in the inspector documentation), but the situation is exactly the same我尝试使用从本地到远程系统的 SSH 隧道,而不是在 RPi 上暴露检查器端口(如检查器文档中所建议的),但情况完全相同

My configuration in launch.json :我在launch.json配置:

            "address": "192.168.178.42",
            "localRoot": "${workspaceFolder}",
            "name": "Attach to Remote",
            "trace": true,
            "port": 9229,
            "remoteRoot": "/home/user/MYCODE",
            "request": "attach",
            "skipFiles": [
                "<node_internals>/**"
            ],
            "type": "pwa-node"
        },

Runtime.launch tag of the remote setup.远程设置的 Runtime.launch 标签。 (the port is included in the URL) (端口包含在 URL 中)

{
    "tag": "runtime.launch",
    "timestamp": 1603657311615,
    "message": "Discovered target URL from /json/list",
    "metadata": {
        "url": "ws://192.168.178.42:9229/c403f26a-422c-4a79-aa59-30b108cc0b51",
        "fixed": "ws://192.168.178.42:9229/c403f26a-422c-4a79-aa59-30b108cc0b51"
    },
    "level": 0
}

Runtime.launch tag of the local setup.本地设置的 Runtime.launch 标签。 (the port is not included in the URL) (端口包含在 URL 中)

{
    "tag": "runtime.launch",
    "timestamp": 1603655650439,
    "message": "Discovered target URL from /json/list",
    "metadata": {
        "url": "ws://localhost/94b1ced4-4eb9-4ca6-a710-c175393f6220",
        "fixed": "ws://localhost:9229/94b1ced4-4eb9-4ca6-a710-c175393f6220"
    },
    "level": 0
}

Could that be the problem?这可能是问题吗?

Finally figured out a potential root cause and solution (I post it here, in case anybody else has a similar problem):终于找出了一个潜在的根本原因和解决方案(我把它贴在这里,以防其他人有类似的问题):

  • Beside the difference above, there was another subtle difference in the diff of the two log files: the local (working) copy reported node version 12, while the other reported nothing at the same location除了上面的区别,两个日志文件的diff还有一个细微的区别:本地(工作)副本报告节点版本12,而另一个在同一位置没有报告
  • Based on that observation, I decided to double-check my node installation: It turned out, that while I had installed node 10 on the Raspberry and verfied the correct installation using nodejs -v , the bash still had the system version node 8 under the default alias node .基于这一观察,我决定仔细检查我的节点安装:结果证明,虽然我已经在 Raspberry 上安装了节点 10 并使用nodejs -v验证了正确的安装,但 bash 在默认别名node
  • After changing that, I could start the debugging session as expected更改后,我可以按预期启动调试会话
  • The documentation for Nodejs 8 already states, that remote debugging with --inspect-brk should work, but obviously, for some reason it does not anymore with my setup. Nodejs 8 的文档已经指出,使用--inspect-brk远程调试应该可以工作,但显然,由于某种原因,我的设置不再适用。
  • I double-confirmed the node version being the root cause by re-installing node 8 using nvm, which brings back the failure我通过使用 nvm 重新安装节点 8 再次确认节点版本是根本原因,这又导致了故障
  • Since node 8 is out of support anyway, this is probably ok - unfortunately, the distribution I use still has it as the system default.由于节点 8 无论如何都不支持,这可能没问题 - 不幸的是,我使用的发行版仍然将它作为系统默认值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM