mxsdev / nvim-dap-vscode-js

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

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

Closed igorlfs closed 1 year ago

igorlfs commented 1 year ago

Hello,

I'm trying to use this plugin, but I can't start a debugging session as I get the error in the title. Here's my config:

-- Packer stuff
    use({
        "mxsdev/nvim-dap-vscode-js",
        config = function()
            require("dap-vscode-js").setup({
                adapters = { "pwa-node", "pwa-chrome", "pwa-msedge", "node-terminal", "pwa-extensionHost" },
            })
        end,
    })
    use({
        "microsoft/vscode-js-debug",
        opt = true,
        run = "npm install --legacy-peer-deps && npm run compile",
    })
...
-- Sample config
dap.configurations.javascript = {
    {
        {
            type = "pwa-node",
            request = "launch",
            name = "Launch Current File (pwa-node)",
            cwd = vim.fn.getcwd(),
            args = { "${file}" },
            sourceMaps = true,
            protocol = "inspector",
        },
    },
}

Am I missing something?

anajuliabit commented 1 year ago

I have the same issue. Did you fixed @igorlfs?

igorlfs commented 1 year ago

I don't know exactly why, but it's working now. Can you try the following config?

for _, language in ipairs({ "typescript", "javascript" }) do
    require"dap".configurations[language] = {
        {
            type = "pwa-node",
            request = "launch",
            name = "Launch file",
            program = "${file}",
            cwd = "${workspaceFolder}",
        },
    }
end

It should be enough to debug JS. If you're using TS, however, it's more tricky, but I got this working:

        {
            type = "pwa-node",
            request = "launch",
            name = "Launch File (ts-node)",
            cwd = vim.fn.getcwd(),
            runtimeArgs = { "--loader", "ts-node/esm" },
            runtimeExecutable = "node",
            args = { "${file}" },
            sourceMaps = true,
            protocol = "inspector",
            skipFiles = { "<node_internals>/**", "node_modules/**" },
            console = "integratedTerminal",
            resolveSourceMapLocations = {
                "${workspaceFolder}/**",
                "!**/node_modules/**",
            },
        },

If you're still getting the nil adapter with these settings, you can try moving your dap-vscode-js' setup to right above where you're setting the dap config, as there might be some lazy loading or some packer magic loading yout dap config before dap-vscode-js is set.

anajuliabit commented 1 year ago

@igorlfs thanks! I'm not sure what was fixed as well, lol, but I guess it happened after I installed vscode-js-debug using Mason. It's called js-debug-adpter there

amircodota commented 1 year ago

I think the issue was the launch config. It had one "curly" too many

You had

dap.configurations.javascript = {
    {
        {
            type = "pwa-node",
            request = "launch",
            name = "Launch Current File (pwa-node)",
            cwd = vim.fn.getcwd(),
            args = { "${file}" },
            sourceMaps = true,
            protocol = "inspector",
        },
    },
}

where it should have been

dap.configurations.javascript = {
        {
            type = "pwa-node",
            request = "launch",
            name = "Launch Current File (pwa-node)",
            cwd = vim.fn.getcwd(),
            args = { "${file}" },
            sourceMaps = true,
            protocol = "inspector",
        },
}