mfussenegger / nvim-dap

Debug Adapter Protocol client implementation for Neovim
GNU General Public License v3.0
5.46k stars 194 forks source link

help needed: manual nvim-dap configuration for javascript works on windows but not on linux #1202

Closed battlelitany closed 5 months ago

battlelitany commented 5 months ago

Debug adapter definition and debug configuration

Hi, I am painfully new to coding/nvim in general, so please forgive me if this is a dumb question. I followed the instructions from here: Javascript Adapter Installation

I got it all set up and working correctly on Windows 11. My configuration file is here at pastebin. I am using Pop OS for Linux. I downloaded the js-debug-dap from the vscode-js-debug release and updated the pathway to dapDebugServer.js.

For whatever reason though, it gives me an error saying it can't connect to localhost. I'm sure it must just be something silly I forgot to do, but I can't figure out how to solve it. I tried looking up help and guides, but most of them show you how to set it up with nvim-dap-vscode-js. I couldn't get that to work though, and my current manual setup already works on Windows, so I'd prefer to stick with it. Any help would be much appreciated!

Debug adapter version

No response

Steps to Reproduce

  1. Enter js file
  2. Set breakpoint
  3. Attempt to run

Expected Result

It shows the nvim-dap-ui on Windows, but will not run on Linux.

Actual Result

node exited with code 1 Couldn't connect to localhost:${port}: ECONNREFUSED

mfussenegger commented 5 months ago

Looks like they changed their default binding logic, and they now only bind to ipv6 ::1 instead of ipv4 127.0.0.1 .

It should work if you change the configuration to:

dap.adapters["pwa-node"] = {
  type = "server",
  host = "::1",
  port = "${port}",
  executable = {
    command = "node",
    args = {"/path/to/js-debug/src/dapDebugServer.js", "${port}"}
  }
}

A good way to debug issues like this is to run the command in the terminal. E.g.:

node src/dapDebugServer.js 1234

Gave the following output:

Debug server listening at ::1:1234
battlelitany commented 5 months ago

Looks like they changed their default binding logic, and they now only bind to ipv6 ::1 instead of ipv4 127.0.0.1 .

It should work if you change the configuration to:

dap.adapters["pwa-node"] = {
  type = "server",
  host = "::1",
  port = "${port}",
  executable = {
    command = "node",
    args = {"/path/to/js-debug/src/dapDebugServer.js", "${port}"}
  }
}

A good way to debug issues like this is to run the command in the terminal. E.g.:

node src/dapDebugServer.js 1234

Gave the following output:

Debug server listening at ::1:1234

I tried this, but unfortunately, it still doesn't work for me. It gives me the same error: Couldn't connect to ::1:${port}: ECONNREFUSED.

Here's my edited configuration:

require("dap").adapters["pwa-node"] = {
   type = "server",
   host = "::1",
   port = "${port}",
   executable = {
   command = "node",
   args = { "/home/user/js-debug/src/dapDebugServer.js", "${port}" },
   },
}

If I run the terminal command, it gives me this output:

node js-debug/src/dapDebugServer.js 1234
Error: listen EADDRINUSE: address already in use ::1:1234
    at Server.setupListenHandle [as _listen2] (node:net:1898:16)
    at listenInCluster (node:net:1946:12)
    at GetAddrInfoReqWrap.doListen [as callback] (node:net:2116:7)
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:109:8) {
  code: 'EADDRINUSE',
  errno: -98,
  syscall: 'listen',
  address: '::1',
  port: 1234
}

EDIT: Also, I tried troubleshooting the error, but when I run lsof -i ::1, I get this readout:

lsof: unknown service :1 in: -i ::1
lsof 4.93.2
 latest revision: https://github.com/lsof-org/lsof
 latest FAQ: https://github.com/lsof-org/lsof/blob/master/00FAQ
 latest (non-formatted) man page: https://github.com/lsof-org/lsof/blob/master/Lsof.8
 usage: [-?abhKlnNoOPRtUvVX] [+|-c c] [+|-d s] [+D D] [+|-E] [+|-e s] [+|-f[gG]]
 [-F [f]] [-g [s]] [-i [i]] [+|-L [l]] [+m [m]] [+|-M] [-o [o]] [-p s]
 [+|-r [t]] [-s [p:s]] [-S [t]] [-T [t]] [-u s] [+|-w] [-x [fl]] [--] [names]

Thank you for such a prompt response, and apologies for troubling you!