Search code examples
node.jsmacosvisual-studio-coderaspberry-piremote-debugging

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. 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. I followed this instruction: https://github.com/BretStateham/pinodevscode I googled 3 evenings already without success. 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). 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.

Here's what I did so far in the Pi setup:

  • followed the instructions in https://github.com/BretStateham/pinodevscode
  • My samba Share is called DEV, mapped to /home/user, my code resides in the subfolder MYCODE
  • I can run my script via SSH on the terminal of the RPi
  • I tried first with the default port 9229, moved to other ports later, follwing a recommendation on a similar post somewhere, but no success
  • 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
  • I have setup a launch configuration based on the template in VSC (see below)
  • 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)
  • The Debugger Buttons (Step Over, Step into, Step out) stay grayed 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.
  • 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
  • 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

My configuration in 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. (the port is included in the 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. (the port is not included in the 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?


Solution

  • 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
    • 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.
    • 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.
    • I double-confirmed the node version being the root cause by re-installing node 8 using nvm, which brings back the failure
    • Since node 8 is out of support anyway, this is probably ok - unfortunately, the distribution I use still has it as the system default.