mxsdev / nvim-dap-vscode-js

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

Error: The selected configuration references adapter `nil`, but dap.adapters.nil is undefined #37

Open frdrkolsson opened 1 year ago

frdrkolsson commented 1 year ago

Hi,

Just set this up and have been debugging it for a couple of hours now to no avail.

Every time I run :lua require('dap').continue with the config down below, I get the message in the title.

The selected configuration references adapter `nil`, but dap.adapters.nil is undefined

The configuration seems to load, but the adapter does not seem to be registered.

The following is my config. Tried with a different couple of setups just to get this started, but none seems to cooperate. Have tried on both .js and .tsx files.

local dap = require('dap')

require("dap-vscode-js").setup({
  debugger_path = os.getenv('HOME') .. '/Code/vscode-js-debug',
  node_path = os.getenv('HOME') .. '.asdf/shims/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' }
})

local js_languages = { "typescript", "javascript", "typescriptreact" }
for _, language in ipairs(js_languages) do
  dap.configurations[language] = {
    {
      {
        type = "pwa-node",
        request = "launch",
        name = "Launch Test Program (pwa-node with vitest)",
        cwd = "${workspaceFolder}",
        program = "${workspaceFolder}/node_modules/vitest/vitest.mjs",
        args = { "--threads", "false", },
        autoAttachChildProcesses = false,
        trace = true,
        console = "integratedTerminal",
        sourceMaps = true,
        smartStep = true,
      },
    }
  }
end

Does anyone see something out of place, or know why none of the adapters from this plugin seems to be setup? My neovim config is available here if anyone is interested into looking deeper into the problem.

jorgerojas26 commented 1 year ago

I'm also having this issue

amircodota commented 1 year ago

Had the same issue.

The problem is that the launch configuration is incorrectly typed. I think we all copied it from some blog post or something, though I am not sure which one.

In any case, the bad configuration is this

dap.configurations[language] = {
    {
      {
        type = "pwa-node",
        request = "launch",
        name = "Launch Test Program (pwa-node with vitest)",
        cwd = "${workspaceFolder}",
        program = "${workspaceFolder}/node_modules/vitest/vitest.mjs",
        args = { "--threads", "false", },
        autoAttachChildProcesses = false,
        trace = true,
        console = "integratedTerminal",
        sourceMaps = true,
        smartStep = true,
      },
    }
  }

Thats' one curly too much :-)

The correct one is this

dap.configurations[language] = {
      {
        type = "pwa-node",
        request = "launch",
        name = "Launch Test Program (pwa-node with vitest)",
        cwd = "${workspaceFolder}",
        program = "${workspaceFolder}/node_modules/vitest/vitest.mjs",
        args = { "--threads", "false", },
        autoAttachChildProcesses = false,
        trace = true,
        console = "integratedTerminal",
        sourceMaps = true,
        smartStep = true,
      },
  }
zettlrobert commented 6 months ago

What works for me is:

      for _, js_filetype in ipairs(js_based_filetypes) do
        dap.configurations[js_filetype] = {
          -- Debug single Vitest
          {
            type = "pwa-node",
            request = "launch",
            name = "Vitest File (pwa-node)",
            autoAttachChildProcesses = true,
            runtimeExecutable = "node",
            runtimeArgs = {
              "${workspaceFolder}/node_modules/vitest/vitest.mjs",
              "--inspect-brk",
              "${file}",
              "--poolOptions.threads.singleThread",
              "true",
            },
            rootPath = "${workspaceFolder}",
            cwd = "${workspaceFolder}",
            console = "integratedTerminal",
            skipFiles = { "<node_internals>/**", "**/node_modules/**" },
          }
        }