mxsdev / nvim-dap-vscode-js

nvim-dap adapter for vscode-js-debug
276 stars 30 forks source link

`EADDRINUSE` when trying to use this with Mason #65

Open kamoshi opened 8 months ago

kamoshi commented 8 months ago

I tried to use this extension with Mason, so I passed it the path from the registry

      local mason = require 'mason-registry'
      local path = mason.get_package('js-debug-adapter'):get_install_path()

However, when trying to attach to a process I get the following error:

[dap-js] JS Debugger stderr: Error: listen EADDRINUSE: address already in use ::1:8123
    at Server.setupListenHandle [as _listen2] (node:net:1893:16)
    at listenInCluster (node:net:1941:12)
    at GetAddrInfoReqWrap.doListen [as callback] (node:net:2096:7)
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:109:8) {
  code: 'EADDRINUSE',
  errno: -98,
  syscall: 'listen',
  address: '::1',
  port: 8123
}
Santiago-Aquino commented 6 months ago

I have the same error. were you able to solve it?

kamoshi commented 6 months ago

I haven't been able to solve this problem, but I found a different way to install JS debugger, not via Mason. This is less than ideal, because you have to build vscode-js-debug yourself and I'm not sure if this still works

{
    'mxsdev/nvim-dap-vscode-js',
    dependencies = {
      'microsoft/vscode-js-debug',
      version = '1.x',
      build = 'npm i && npm run compile vsDebugServerBundle && mv dist out',
    },
    config = function()
      local dap = require 'dap'
      --local utils = require 'dap.utils'
      local dap_js = require 'dap-vscode-js'
      --local mason = require 'mason-registry'

      ---@diagnostic disable-next-line: missing-fields
      dap_js.setup {
        -- debugger_path = mason.get_package('js-debug-adapter'):get_install_path(),
        debugger_path = vim.fn.stdpath 'data' .. '/lazy/vscode-js-debug',
        adapters = { 'pwa-node', 'pwa-chrome', 'pwa-msedge', 'node-terminal', 'pwa-extensionHost' },
      }

      local langs = { 'javascript', 'typescript', 'svelte', 'astro' }
      for _, lang in ipairs(langs) do
        dap.configurations[lang] = {
          {
            type    = 'pwa-node',
            request = 'attach',
            name    = 'Attach debugger to existing `node --inspect` process',
            cwd     = '${workspaceFolder}',
            skipFiles = {
              '${workspaceFolder}/node_modules/**/*.js',
              '${workspaceFolder}/packages/**/node_modules/**/*.js',
              '${workspaceFolder}/packages/**/**/node_modules/**/*.js',
              '<node_internals>/**',
              'node_modules/**',
            },
            sourceMaps = true,
            resolveSourceMapLocations = {
              '${workspaceFolder}/**',
              '!**/node_modules/**',
            },
          },
        }
      end
    end,
  },
petergi commented 3 months ago

Good god! I've spent hours fiddling with this. I almost gave up until I stumbled onto this... Thank you!

TylerBarnes commented 1 month ago

As far as I can tell this isn't related to mason, see my comment here https://github.com/mxsdev/nvim-dap-vscode-js/issues/43#issuecomment-2292493558

I'm not sure why @kamoshi 's answer used to work but it doesn't seem to anymore - maybe they released the same bug in version = '1.x', later?