mxsdev / nvim-dap-vscode-js

nvim-dap adapter for vscode-js-debug
266 stars 24 forks source link

Got error "adapter.port is required for server adapter" when using manson installed vscode-js-debug #58

Closed BilderLoong closed 4 months ago

BilderLoong commented 10 months ago

My lazy.nvim plugin config:

{
    "mxsdev/nvim-dap-vscode-js",
    ft = { "javascript", "javascriptreact", "typescript", "typecriptreact" },
    dependencies = { "mfussenegger/nvim-dap" },
    opts = function(_, default_nvchad_opts)
      return {
        node_path = "node",
        debugger_cmd = { "js-debug-adapter" }, -- Command to use to launch the debug server. Takes precedence over `node_path` and `debugger_path`.
        adapters = { "pwa-node", "pwa-chrome", "pwa-msedge", "node-terminal", "pwa-extensionHost", "node", "chrome" },
      }
    end,
    config = function(_, opts)
      require("dap-vscode-js").setup(opts)

      for _, language in ipairs { "typescript", "javascript" } do
        require("dap").configurations[language] = {
          {
            type = "pwa-node",
            request = "attach",
            name = "Attach",
            processId = require("dap.utils").pick_process,
            cwd = "${workspaceFolder}",
          },
          {
            -- use nvim-dap-vscode-js's pwa-node debug adapter
            type = "pwa-node",
            -- launch a new process to attach the debugger to
            request = "launch",
            -- name of the debug action you have to select for this config
            name = "Launch current file in new node process (" .. language .. ")",
            program = "${file}",
            cwd = "${workspaceFolder}",
          },
        }
      end
    end,
  }

Full error message:

Error executing luv callback:
...rudo/.local/share/nvim/lazy/nvim-dap/lua/dap/session.lua:1307: adapter.port is required for server adapter
stack traceback:
        [C]: in function 'assert'
        ...rudo/.local/share/nvim/lazy/nvim-dap/lua/dap/session.lua:1307: in function <...rudo/.local/share/nvim/lazy/nvim-dap/lua/dap/session.lua:1299>
Press ENTER or type command to continue
BilderLoong commented 10 months ago

I think this error is because the lua pattern used to extract the debug server port

https://github.com/mxsdev/nvim-dap-vscode-js/blob/03bd29672d7fab5e515fc8469b7d07cc5994bbf6/lua/dap-vscode-js/utils.lua#L117 isn't compatible with the output of the js-debug-adapter which actually run the js-debug/src/dapDebugServer.js file. Output of running js-debug-adapter.

$ cat js-debug-adapter
#!/usr/bin/env bash

exec node "/Users/birudo/.local/share/nvim/mason/packages/js-debug-adapter/js-debug/src/dapDebugServer.js" "$@"%

$ ./js-debug-adapter
Debug server listening at 127.0.0.1:8123
BilderLoong commented 10 months ago

Related to https://github.com/mxsdev/nvim-dap-vscode-js/issues/57.

carlos-algms commented 4 months ago

Hey @BilderLoong, there have been no new commits to this repo since last Year. Could you point out the solution you got? Thanks.

navignaw commented 1 week ago

@carlos-algms I followed the workaround in https://github.com/mxsdev/nvim-dap-vscode-js/issues/57#issue-1890647297 to lock to version 1.76.1 to fix the issue. If you use https://github.com/jay-babu/mason-nvim-dap.nvim then the solution would look something like

require("mason-nvim-dap").setup({
  automatic_installation = false,
  ensure_installed = {
    -- Due to a bug with the latest version of vscode-js-debug, need to lock to specific version
    -- See: https://github.com/mxsdev/nvim-dap-vscode-js/issues/58#issuecomment-2213230558
    "js@v1.76.1",
  },
})

Or if you install it manually, MasonInstall js-debug-adapter@v1.76.1 (you may need to run MasonUninstall first to remove the later version)