Giter VIP home page Giter VIP logo

nvim-dap-vscode-js's Introduction

nvim-dap-vscode-js

nvim-dap adapter for vscode-js-debug.

Adapters

Every platform supported by vscode is provided. This includes:

Adapter Platform Support
pwa-node Node.js Full
pwa-chrome Chrome Partial1
pwa-msedge Edge Untested
node-terminal Node.js Untested
pwa-extensionHost VSCode Extensions Untested

Installation

Plugin

Supports packer, vim-plug, etc. With packer, for example:

use { "mxsdev/nvim-dap-vscode-js", requires = {"mfussenegger/nvim-dap"} }

Debugger

You must download and build a copy of vscode-js-debug in order to use this plugin.

With Packer

use {
  "microsoft/vscode-js-debug",
  opt = true,
  run = "npm install --legacy-peer-deps && npx gulp vsDebugServerBundle && mv dist out" 
}

Manually

git clone https://github.com/microsoft/vscode-js-debug
cd vscode-js-debug
npm install --legacy-peer-deps
npx gulp vsDebugServerBundle
mv dist out

Note: The upstream build process has changed sometime since the creation of this repo. If the above scripts don't work, please make sure you're using the latest version of vscode-js-debug. Otherwise, feel free to file an issue!

Setup

require("dap-vscode-js").setup({
  -- node_path = "node", -- Path of node executable. Defaults to $NODE_PATH, and then "node"
  -- debugger_path = "(runtimedir)/site/pack/packer/opt/vscode-js-debug", -- Path to vscode-js-debug installation.
  -- 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' }, -- which adapters to register in nvim-dap
  -- log_file_path = "(stdpath cache)/dap_vscode_js.log" -- Path for file logging
  -- log_file_level = false -- Logging level for output to file. Set to false to disable file logging.
  -- log_console_level = vim.log.levels.ERROR -- Logging level for output to console. Set to false to disable console output.
})

for _, language in ipairs({ "typescript", "javascript" }) do
  require("dap").configurations[language] = {
    ... -- see below
  }
end

Note that if vscode-js-debug was installed without packer, its root folder location must be set manually in debugger_path.

Configurations

See here for all custom configuration options.

Node.js

{
  {
    type = "pwa-node",
    request = "launch",
    name = "Launch file",
    program = "${file}",
    cwd = "${workspaceFolder}",
  },
  {
    type = "pwa-node",
    request = "attach",
    name = "Attach",
    processId = require'dap.utils'.pick_process,
    cwd = "${workspaceFolder}",
  }
}

Jest2

{
  {
    type = "pwa-node",
    request = "launch",
    name = "Debug Jest Tests",
    -- trace = true, -- include debugger info
    runtimeExecutable = "node",
    runtimeArgs = {
      "./node_modules/jest/bin/jest.js",
      "--runInBand",
    },
    rootPath = "${workspaceFolder}",
    cwd = "${workspaceFolder}",
    console = "integratedTerminal",
    internalConsoleOptions = "neverOpen",
  }
}

You may also want to check out neotest-jest, which supports this plugin out of the box.

Mocha

{
  {
    type = "pwa-node",
    request = "launch",
    name = "Debug Mocha Tests",
    -- trace = true, -- include debugger info
    runtimeExecutable = "node",
    runtimeArgs = {
      "./node_modules/mocha/bin/mocha.js",
    },
    rootPath = "${workspaceFolder}",
    cwd = "${workspaceFolder}",
    console = "integratedTerminal",
    internalConsoleOptions = "neverOpen",
  }
}

Planned Features

  • Integration with neotest-jest
  • Support for switching between child sessions

Credits

I would like to say a huge thank you to Jens Claes, whose dotfiles this plugin is based off of, and to all members who contributed to this issue - the insight gained from this was paramount to the success of this project.

Footnotes

  1. The debugger runs and attaches, however breakpoints may be rejected.

  2. See here for more details on running jest

nvim-dap-vscode-js's People

Contributors

entropitor avatar mfussenegger avatar mxsdev avatar nfrid avatar williamboman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

nvim-dap-vscode-js's Issues

Node process doesn't get killed when terminating a debug session

When I try to run a debug session of a basic node server, I can debug it just fine. But when I terminate the session (require('dap').terminate()) or disconnect from it (require('dap').disconnect({ terminateDebuggee = true })) and then rerun a new session, I get an error about the node server port being already in use, meaning, that the previous node process wasn't properly closed. I'm clueless about what to do ☹️

I've got the following config:

local DEBUGGER_PATH = vim.fn.stdpath('data') .. '/lazy/vscode-js-debug'

require('dap-vscode-js').setup({
  debugger_path = DEBUGGER_PATH,
  adapters = {
    'pwa-node',
    'pwa-chrome',
    'node-terminal',
  },
})

local dap = require('dap')

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

The installed version of vscode-js-debug is 1.78.0

Support variable entry-point file name?

The entry-point file name is hard-coded here :

return M.join_paths(debugger_path, "out/src/vsDebugServer.js")

But it may change depending on the version and installation tool used. For my case, I installed js-debug-adapter using mason and the bin path is defined here.

What do you think of making the file path out/src/vsDebugServer.js also configurable just like debugger_path so it can be changed as needed for other installation processes?

Feature request: setting default value for `launch.json` configuration value

Thanks for a great plugin! I spent some time trying to figure out why a launch.json file wasn't working properly when my very similar hard-coded dap configuration in my Lua config worked. Turns out that the launch.json files that my team at work use don't have "cwd": "${workspaceFolder}" in them, but my hard-coded config configuration did.

I feel like "${workspaceFolder}" is a reasonable default value to have for "cwd", so I'm wondering now what the default is. It feels odd to have to add this to every config in every launch.json that we use so I think it would be a great feature if nvim-dap-vscode-js let me specify the default value to use for "cwd" in this case if it isn't specified in the launch.json file.

What do you think?

Getting errors on attach

When I try to attach to a process with running ts-node server, i get an error. I've tried to change the port in the server setup in attach method, but I keep getting the same erorr.
2023-03-08-100333_2009x33_escrotum
Is there a step by step guide for debbuging node server?

Setup help using inspector to debug nodejs api

I have installed dap, dapui and this in my neovim config.

However im finding it difficult getting this working:

  1. i run my api using ts-node-dev --inspect --respawn -r tsconfig-paths/register src/server.ts
Debugger listening on ws://127.0.0.1:9229/7620bcc9-36ab-4879-85d8-d398a50a5f45
Server Running On: 0.0.0.0:3003
  1. Then set a breakpoint using leader+b

image

  1. When i make a request (in postman), i expect it should begin debugging but it does not.

I'm not sure what im doing wrong :/ (Im trying to do something like this https://www.youtube.com/watch?v=ga3Cas7vNCk)

nnoremap <silent> <F5> <Cmd>lua require'dap'.continue()<CR>
nnoremap <silent> <F10> <Cmd>lua require'dap'.step_over()<CR>
nnoremap <silent> <F11> <Cmd>lua require'dap'.step_into()<CR>
nnoremap <silent> <F12> <Cmd>lua require'dap'.step_out()<CR>
nnoremap <silent> <Leader>b <Cmd>lua require'dap'.toggle_breakpoint()<CR>
nnoremap <silent> <Leader>B <Cmd>lua require'dap'.set_breakpoint(vim.fn.input('Breakpoint condition: '))<CR>
nnoremap <silent> <Leader>lp <Cmd>lua require'dap'.set_breakpoint(nil, nil, vim.fn.input('Log point message: '))<CR>
nnoremap <silent> <Leader>dr <Cmd>lua require'dap'.repl.open()<CR>
nnoremap <silent> <Leader>dl <Cmd>lua require'dap'.run_last()<CR>


lua <<EOF

local dap, dapui = require("dap"), require("dapui")
dap.listeners.after.event_initialized["dapui_config"] = function()
  dapui.open()
end
dap.listeners.before.event_terminated["dapui_config"] = function()
  dapui.close()
end
dap.listeners.before.event_exited["dapui_config"] = function()
  dapui.close()
end

require("dap-vscode-js").setup({
  -- node_path = "node", -- Path of node executable. Defaults to $NODE_PATH, and then "node"
  -- debugger_path = "(runtimedir)/site/pack/packer/opt/vscode-js-debug", -- Path to vscode-js-debug installation.
  -- 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' }, -- which adapters to register in nvim-dap
  -- log_file_path = "(stdpath cache)/dap_vscode_js.log" -- Path for file logging
  -- log_file_level = false -- Logging level for output to file. Set to false to disable file logging.
  -- log_console_level = vim.log.levels.ERROR -- Logging level for output to console. Set to false to disable console output.
})

for _, language in ipairs({ "typescript", "javascript" }) do
  dap.configurations[language] = {
      {
        type = "pwa-chrome",
        request = "attach",
        name = "Attach",
        processId = require'dap.utils'.pick_process,
        cwd = "${workspaceFolder}",
      }
  }
end


EOF

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

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.

Error trying to launch JS debugger: EACCES: permission denied

When installing, Error trying to launch JS debugger: EACCES: permission denied is thrown when I try to launch the debugger. It seems that it happens with both recommended installation methods (manual and with packer).

My $USER have access to the file.
-rwxrwxr-x 1 myUser myUser 5635 août 27 00:24 vsDebugServer.js

AVA Support

Hi, I'm trying to run AVA test with DAP.

I tried the example configuration in the documentation. It works well with VSCode but in NVim it starts the program but do not stop on breakpoints.

I also tried a generic config with npm test:

{
    type = "pwa-node",
    request = "launch",
    name = "Run NPM test",
    cwd = "${workspaceFolder}",
    runtimeExecutable = "npm",
    runtimeArgs = {
      "test"
    },
    trace = true,
    outputCapture = "std",
    console = "integratedTerminal",
    outFiles = {
      "${workspaceFolder}/dist/*.js",
      "!**/node_modules/**"
    }
  }

but I got the same results.

I tried to add a --inspect in the runtimeArgs but I get an error because the inspector is already started. Again, this config works well with VSCode.

Can you point me to a difference between VSCode and DAP that can leads to this?

Thank you

typescript support

Hello,
Any idea how to make it work for typescript? It just simply breaks at current state like

import * as fs from 'fs';
^^^^^^

SyntaxError: Cannot use import statement outside a module

@@edit
ok, figured it out by myself, maybe it will be helpfull for someone else
simply add in config ts-node executable path, or if its already included in PATH just "ts-node"

{
    ....
    runtimeExecutable = "ts-node", 
    ...
}

Please help -- looking for in-depth example of using `google-chrome-stable` with `nvim-dap` and `microsoft/vscode-js-debug`

This is a super-common stack which is directly supported by this codebase, so it would be beyond rad if we could have a substantial example in the docs showing how to combine these:

  • Google Chrome (On my NixOS machine, that's google-chrome-stable)
  • Neovim
  • Nvim-dap
  • vscode-js-debug

TBH I'm stumped -- I keep getting:

image

I have a slightly idiosyncratic way of grouping dependencies everything works except specifically nvim-dap-vscode-js, and my intuition, plus having attempted various other options, including program, with the same result, suggests that the problem is with how I've configured nvim-dap-vscode-js rather than Packer.

EDIT After rereading the message above, I need to clarify that I've naively played with specifying a lot of options, including the obvious address and server, but with no change in error. I figured I'd make a minimally reproducible example. What am I getting wrong below?

  use { "mfussenegger/nvim-dap",
    requires = { 
       "mxsdev/nvim-dap-vscode-js",
       { "microsoft/vscode-js-debug", opt = true, run = "npm install --legacy-peer-deps && npm run compile" },
     },
    config = function()
      require "dap-vscode-js".setup({
        adapters = { 'pwa-chrome' },
        log_file_path = "/tmp/dap_vscode_js.log",
        log_file_level = vim.log.levels.INFO
        log_console_level = vim.log.levels.INFO
      })
      for _, language in ipairs({ "typescript", "javascript", "typescriptreact", "javascriptreact" }) do
        require("dap").configurations[language] = {
          {
            type = "pwa-chrome",
            request = "launch",
            name = "Chrome Launch",
          },
        }
     end
    end
  }

Error trying to launch JS debugger: EACCES: permission denied

Hello! I would like to know how I can debug this issue.

Issue

This is all the information I was given.

Using cat on the log output after setting the log_level to 4 gives me the following output:

[ERROR qua 19 jul 2023 19:21:50 27324356607905] ...im/lazy/nvim-dap-vscode-js/lua/dap-vscode-js/adapter.lua:72: Error trying to launch JS debugger: EACCES: permission denied

(the ... came together)

I'm also able to see it in the terminal:

image

Attempts

Just to be sure, I tried to run sudo chmod +rx -R ./directory where directory was every folder related do dap that I have here.

Output of ls -l on the dap files:

drwxrwxr-x  8 hugo hugo 4096 jul 19 16:09 nvim-dap
drwxrwxr-x  8 hugo hugo 4096 jul 19 16:16 nvim-dap-ui
drwxrwxr-x  7 hugo hugo 4096 jul 19 16:35 nvim-dap-virtual-text
drwxrwxr-x  8 hugo hugo 4096 jul 19 17:16 nvim-dap-vscode-js
drwxrwxr-x 12 hugo hugo 4096 jul 19 19:20 vscode-js-debug

I also tried to edit the project on my own to use logger.error to see in which line the error happens, but my nvim failed to start with the edited project. Thus, I abandoned this approach.

Setup information

Operational System

Distributor ID:	Ubuntu
Description:	Ubuntu 22.04.2 LTS
Release:	22.04
Codename:	jammy

Neovim

NVIM v0.10.0-dev-530+g8376e8700
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3
Compilation: /usr/bin/cc -O2 -g -Og -g -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wvla -Wdouble-promotion -Wmissing-noreturn -Wmissing-format-attribute -Wmissing-prototypes -fno-common -Wno-unused-result -Wimplicit-fallthrough -fdiagnostics-color=always -fstack-protector-strong -DUNIT_TESTING -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_TS_HAS_SET_MAX_START_DEPTH -I/build/nvim/parts/nvim/build/.deps/usr/include/luajit-2.1 -I/usr/include -I/build/nvim/parts/nvim/build/.deps/usr/include -I/build/nvim/parts/nvim/build/build/src/nvim/auto -I/build/nvim/parts/nvim/build/build/include -I/build/nvim/parts/nvim/build/build/cmake.config -I/build/nvim/parts/nvim/build/src

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/usr/share/nvim"

Everything related to dap is in the most recent changes of the master branches.


Let me know if you need more information. Plus, feel free to reach me on Discord hugobsb.

Auto Attach is possible?

Problem Statement

Hi, I've been configuring my nvim to debug on my editor a next.js app. And it works by starting a dev server with node options for debugging like this:

NODE_OPTIONS='--inspect' pnpm dev

But I was wondering if it's possible to launch a next server from nvim like VSCode does.
This is my launch.json in VSCode

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Next.js: (node-terminal)",
      "type": "node-terminal",
      "request": "launch",
      "command": "pnpm dev"
    }
  ]
}

This starts the server inside VSCode and the debugger is up and running
image

So you this would be possible use nvim-dap?

Thanks for this awesome project!

Possible Solutions

No idea.

Considered Alternatives

The alternative is to use NODE_OPTIONS in a terminal and then attach to that next server. Is fine but it would be awesome to be able to launch the server and attach within nvim.

Installation incomplete?

Hi, I just wanted to try this plugin out, but cannot install it.
The instructions include running npm install, but there is no package.json so it just fails.

Break points do not work

Hey! First of all thx for your work.

For me for some reasons breakpoints do not work when i use this adapter(they work with node2 adapter but some other stuff do not)

I am able to connect to debugger and see remote process in DAP, but for some reason breakpoints are ignored.

Logs

[ INFO ] 2022-11-13T15:27:37Z+0100 ] ...eginin/.config/nvim/plugged/nvim-dap/lua/dap/session.lua:705 ]  "Telemetry" "js-debug/launch"
~                                       │ 18 [ INFO ] 2022-11-13T15:27:50Z+0100 ] ...eginin/.config/nvim/plugged/nvim-dap/lua/dap/session.lua:705 ]  "Telemetry" "js-debug/dap/operation"
~                                       │ 17
~                                       │ 16 [ INFO ] 2022-11-13T15:28:03Z+0100 ] ...eginin/.config/nvim/plugged/nvim-dap/lua/dap/session.lua:705 ]  "Telemetry" "js-debug/launch"
~                                       │ 15 [ INFO ] 2022-11-13T15:28:03Z+0100 ] ...eginin/.config/nvim/plugged/nvim-dap/lua/dap/session.lua:705 ]  "Telemetry" "js-debug/nodeRuntime"
~                                       │ 14 [ INFO ] 2022-11-13T15:28:07Z+0100 ] ...eginin/.config/nvim/plugged/nvim-dap/lua/dap/session.lua:705 ]  "Telemetry" "js-debug/dap/operation"
~                                       │ 13 [ INFO ] 2022-11-13T15:28:07Z+0100 ] ...eginin/.config/nvim/plugged/nvim-dap/lua/dap/session.lua:705 ]  "Telemetry" "js-debug/cdp/operation"
~                                       │ 12 [ INFO ] 2022-11-13T15:28:08Z+0100 ] ...eginin/.config/nvim/plugged/nvim-dap/lua/dap/session.lua:705 ]  "Telemetry" "js-debug/dap/operation"
~                                       │ 11 [ INFO ] 2022-11-13T15:28:19Z+0100 ] ...eginin/.config/nvim/plugged/nvim-dap/lua/dap/session.lua:705 ]  "Telemetry" "js-debug/cdp/operation"
~                                       │ 10 [ INFO ] 2022-11-13T15:28:19Z+0100 ] ...eginin/.config/nvim/plugged/nvim-dap/lua/dap/session.lua:705 ]  "Telemetry" "js-debug/dap/operation"
~                                       │  9 [ INFO ] 2022-11-13T15:28:24Z+0100 ] ...eginin/.config/nvim/plugged/nvim-dap/lua/dap/session.lua:705 ]  "Telemetry" "js-debug/cdp/operation"
~                                       │  8 [ INFO ] 2022-11-13T15:28:30Z+0100 ] ...eginin/.config/nvim/plugged/nvim-dap/lua/dap/session.lua:705 ]  "Telemetry" "js-debug/cdp/operation"
~                                       │  7 [ INFO ] 2022-11-13T15:28:36Z+0100 ] ...eginin/.config/nvim/plugged/nvim-dap/lua/dap/session.lua:705 ]  "Telemetry" "js-debug/cdp/operation"
~                                       │  6 [ INFO ] 2022-11-13T15:28:42Z+0100 ] ...eginin/.config/nvim/plugged/nvim-dap/lua/dap/session.lua:705 ]  "Telemetry" "js-debug/cdp/operation"
~                                       │  5 [ INFO ] 2022-11-13T15:28:49Z+0100 ] ...eginin/.config/nvim/plugged/nvim-dap/lua/dap/session.lua:705 ]  "Telemetry" "js-debug/cdp/operation"
~                                       │  4 [ INFO ] 2022-11-13T15:28:55Z+0100 ] ...eginin/.config/nvim/plugged/nvim-dap/lua/dap/session.lua:705 ]  "Telemetry" "js-debug/cdp/operation"
~                                       │  3 [ INFO ] 2022-11-13T15:29:01Z+0100 ] ...eginin/.config/nvim/plugged/nvim-dap/lua/dap/session.lua:705 ]  "Telemetry" "js-debug/cdp/operation"
~                                       │  2 [ INFO ] 2022-11-13T15:29:08Z+0100 ] ...eginin/.config/nvim/plugged/nvim-dap/lua/dap/session.lua:705 ]  "Telemetry" "js-debug/cdp/operation"
~                                       │  1 [ INFO ] 2022-11-13T15:29:14Z+0100 ] ...eginin/.config/nvim/plugged/nvim-dap/lua/dap/session.lua:705 ]  "Telemetry" "js-debug/cdp/operation"
~                                       │517 [ INFO ] 2022-11-13T15:29:20Z+0100 ] ...eginin/.config/nvim/plugged/nvim-dap/lua/dap/session.lua:705 ]  "Telemetry" "js-debug/cdp/operation"

Config

for _, language in ipairs({ "typescript", "javascript" }) do
  require("dap").configurations[language] = {
    {
      type = "pwa-node",
      request = "attach",
      localRoot = "${workspaceFolder}",
      remoteRoot = "/",
      cwd = "${workspaceFolder}",
      name = "dev-env: service debugger",
      resolveSourceMapLocations = { "${workspaceFolder}/dist/**/*.js", "${workspaceFolder}/**", "!**/node_modules/**" },
      sourceMaps = true,
      protocol = "inspector",
      console = "integratedTerminal",
      port = 9229
    },
  }
end

JFYI works with the same config in vscode

JS debugger not working

I am trying to debug my typescript file. And using lunar-vim btw. and getting the following error:

Error

image

[dap-js] Error trying to launch js-debugger: EONENT: No such file or directory.

My dap configuration

require('dap-vscode-js').setup({
  debugger_path = '~/.local/share/lvim/mason/packages/js-debug-adapter',
  debugger_cmd = { 'js-debug-adapter' },
  adapters = { 'pwa-node', 'pwa-chrome', 'pwa-msedge', 'node-terminal', 'pwa-extensionHost' },
  node_path = 'node'
})

local dap_status_ok, dap = pcall(require, "dap")
if not dap_status_ok then
  return
end

for _, language in ipairs({ "typescript", "javascript" }) do
  dap.configurations[language] = {
    {
      type = "pwa-node",
      request = "launch",
      name = "Debug TypeScript",
      program = "${workspaceFolder}/path/to/your/ts-file.ts",
      runtimeExecutable = "node",
      runtimeArgs = { "-r", "ts-node/register" },
      outFiles = { "${workspaceFolder}/path/to/your/ts-file.js" },
      sourceMaps = true,
      stopOnEntry = false,
      args = {},
      cwd = "${workspaceFolder}",
      protocol = "inspector",
      console = "integratedTerminal",
      internalConsoleOptions = "openOnSessionStart"
    },
    {
      type = "pwa-node",
      request = "launch",
      name = "Launch file",
      program = "${file}",
      cwd = "${workspaceFolder}",
      sourceMaps = true,
      skipFiles = { "<node_internals>/**", "node_modules/**" },
    },
    {
      type = "pwa-node",
      request = "attach",
      name = "Attach",
      processId = require 'dap.utils'.pick_process,
      cwd = "${workspaceFolder}",
    } }
end

Vitest support

Hi,
Thank you for this plugin!
Is debugging vite-tests supported? I tried to make it run with the following config, and the debugger attaches but from there on, things are broken:
The "DAP Scopes" buffer (I use dap-ui) holds the state of the objects at the first breakpoint, and dap-ui indicates that it stopped at the first breakpoint. However, as soon as I try to step forward, a notification appears DAP ERROR No stopped threads. Cannot move

The configuration I used is:

    {
        type = "pwa-node",
        request = "launch",
        name = "Debug Current Test File",
        autoAttachChildProcesses = true,
        skipFiles = { "<node_internals>/**", "**/node_modules/**" },
        program = "${workspaceFolder}/node_modules/vitest/vitest.mjs",
        runtimeExecutable = "node",
        rootPath = "${workspaceFolder}",
        cwd = "${workspaceFolder}",
        args = { "run", "${relativeFile}" },
        smartStep = true,
        console = "integratedTerminal",
        internalConsoleOptions = "neverOpen",
    },

The plugin works well when debugging a simple node application so I think I set it up correctly.
The configuration is based on the official instruction from vite to setup debugging in vs code so I hoped that it would work for nvim dap as well.

Avoid Scratch Buffer

Hi 👋 ,

First of all, thanks for this nice plugin, it works very well, also in combination with my plugin jester.

One thing that bothers me a bit is that when debugging Jest tests, the debugger always stops in a readonly scratch buffer, hence it's not possible to perform some ad-hoc changes. On the other hand, the node2 debugger directly stops in the same file where the breakpoint is set making the whole experience better.

Do you know of any way to prevent stopping in scratch buffers?

Note:
The scratch buffers for the jest test themselves are transformed, I tried to prevent this using the Jest config

const config = {
  verbose: true,
  transform: {},
  transformIgnorePatterns: ["."]
};

module.exports = config;

but it didn't help.

Thanks again and best regards,
David

Getting error: adapter.port is required for server adapter

I've tried to get debugging in jest working but im getting the following error.

Error executing luv callback:                                                                                                                                                                                                                                                                                                                                                               
.../.local/share/nvim/lazy/nvim-dap/lua/dap/session.lua:1223: adapter.port is required for server adapter                                                                                                                                                                                                                                                                               
stack traceback:                                                                                                                                                                                                                                                                                                                                                                            
        [C]: in function 'assert'                                                                                                                                                                                                                                                                                                                                                           
        .../.local/share/nvim/lazy/nvim-dap/lua/dap/session.lua:1223: in function <...hNoe/.local/share/nvim/lazy/nvim-dap/lua/dap/session.lua:1215>  

Im using lazy as a package manager with the following config:

local M = {
  "mfussenegger/nvim-dap",
  dependencies = {
    { "rcarriga/nvim-dap-ui" },
    {
      "mxsdev/nvim-dap-vscode-js",
      tag = "v1.1.0",
    },
    {
      "microsoft/vscode-js-debug",
      tag = "v1.74.1",
      build =
      "npm install --legacy-peer-deps && npx gulp vsDebugServerBundle && mv dist out"
    },
  },
  keys = { 
  -- Snippet out for brevity
  }
}

M.config = function()
  require('dap-vscode-js').setup({
    debugger_path = vim.fn.stdpath('data') .. '/lazy/packages/vscode-js-debug',
    debugger_cmd = { 'js-debug-adapter' },
    adapters = { 'pwa-node', 'pwa-chrome', 'pwa-msedge', 'node-terminal', 'pwa-extensionHost' },
  })

  local dap = require('dap')

  -- language config
  for _, language in ipairs({ 'typescript', 'javascript' }) do
    dap.configurations[language] = {
      {
        type = "pwa-node",
        request = "launch",
        name = "Debug Jest Tests",
        -- trace = true, -- include debugger info
        runtimeExecutable = "node",
        runtimeArgs = {
          "./node_modules/jest/bin/jest.js",
          "--runInBand",
        },
        rootPath = "${workspaceFolder}",
        cwd = "${workspaceFolder}",
        console = "integratedTerminal",
        internalConsoleOptions = "neverOpen"
      }
    }
  end
end

return M

I've tried building both nvim-dap-vscode-js and vscode-js-debug with specific versions and latest commit.

Any help will be much appreciated

Server not closing after terminating

Hi.
I've finally gotten debugging working (well, almost).
It works the first time, however when I debug a node server and terminate, it doesn't close the server.
Im using LazyVim with nvim dap extras.
I use dap-vscode-js for the setups, which is basically taken straight out of the docs:

require("dap-vscode-js").setup({
  adapters = { "pwa-node" },
})

for _, language in ipairs({ "typescript", "javascript" }) do
  require("dap").configurations[language] = {
    {
      type = "pwa-node",
      request = "launch",
      name = "ts-node",
      program = "${workspaceFolder}/node_modules/ts-node/dist/bin.js",
      sourceMaps = true,
      args = { "${workspaceFolder}/src/index.ts" },
      cwd = vim.fn.getcwd(),
      env = {
        NODE_ENV = "dev",
      },
    },
    {
      type = "pwa-node",
      request = "launch",
      name = "ts-node-dev",
      program = "${workspaceFolder}/node_modules/ts-node/dist/bin.js",
      sourceMaps = true,
      args = { "${workspaceFolder}/src/index.ts" },
      cwd = vim.fn.getcwd(),
    },
    {
      type = "pwa-node",
      request = "launch",
      name = "PBL",
      program = "${file}",
      cwd = "${workspaceFolder}",
    },
  }
end

So at first run, the debugger starts up the server. When I terminate everything looks fine.
When I start up again, the port is in use.
When I kill the port and start the debugger again, it works until next time I terminate.

The same launch scripts works perfectly in vscode.

Any suggestions?
Im happy to give more information about my setup if needed, but as I have no idea what's going on I don't know what to provide :D

How to fix `port` `undefined`

Do not use latest commit https://github.com/microsoft/vscode-js-debug . use v1.74.1.

Error

[dap-js] JS Debugger stderr:
[dap-js] JS Debugger stderr: /path-to/vscode-js-debug/src/vsDebugServer.ts:93                                                                                                                 
    console.log((result.server.address() as net.AddressInfo).port.toString());                                                                                                                                                                
                                                                 ^                                                                                                                                                                            
TypeError: Cannot read properties of undefined (reading 'toString')                                                                                                                                                                           
    at VsDebugServer.launchRoot (/path-to/vscode-js-debug/src/vsDebugServer.ts:93:66)                                                                                                         
    at processTicksAndRejections (node:internal/process/task_queues:95:5)     
[dap-js] JS Debugger exited with code 1! 

Manually

git clone https://github.com/microsoft/vscode-js-debug
cd vscode-js-debug
git pull
git fetch --all --tags
git checkout tags/v1.74.1
npm install --legacy-peer-deps
npm run compile

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

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

Change of entrypoint when installed using Mason

Newer versions of the vscode-js-debug seem to have alternate builds.

Mason uses the dapDebugServer build rather than the older vsDebugServer. This means that for versions after 1.76.1 of vscode-js-debug there is no '/out/src/vsDebugServer.js', instead the path is Entrypoint path is now js-debug/src/dapDebugServer.js

I suspect the easiest thing will be to update to allow a configurable entry point relative to the debugger_path.

For now those using mason-dap-nvim to install vscode-js-debug can use version 1.76.1 instead of the latest 1.82

How to open debugger terminal?

I'd like to be able to open a debugger terminal similar to how is done in vscode, so that I can try debugging npm or node scripts from a terminal. However, I'm struggling to digest how to set up this configuration based on the configurations given.

image

I've tried to set up my configuration as follows, with the node-terminal configured. However, when I select this option is seems to briefly open some buffers before immediately closing them.

    -- using lazy
    {
        "mxsdev/nvim-dap-vscode-js",
        config = function()
            local utils = require("dap-vscode-js.utils")
            require("dap-vscode-js").setup {
                adapters = { 'pwa-node', 'pwa-chrome', 'pwa-msedge', 'node-terminal', 'pwa-extensionHost' },
                debugger_path = utils.join_paths(utils.get_runtime_dir(), "lazy/vscode-js-debug"),
            }
            require("custom.configs.nvim-dap-vscode-js")
        end,
        dependencies = {
            "mfussenegger/nvim-dap",
            "rcarriga/nvim-dap-ui",
            {
                "microsoft/vscode-js-debug",
                build = "npm install --legacy-peer-deps && npx gulp vsDebugServerBundle && mv dist out",
            }
        },
        ft = "javascript",
    },
-- custom/configs/nvim-dap-vscode-js.lua
for _, language in ipairs({ "typescript", "javascript" }) do
    require("dap").configurations[language] = {
        {
            type = "pwa-node",
            request = "launch",
            name = "Launch file",
            program = "${file}",
            cwd = "${workspaceFolder}",
        },
        {
            type = "pwa-node",
            request = "launch",
            name = "Attach",
            processId = require("dap.utils").pick_process,
            cwd = "${workspaceFolder}",
        },
        {
            type = "node-terminal",
            request = "launch",
            name = "Launch terminal",
            cwd = "${workspaceFolder}",
        }
    }
end

Starting/Running debuger throw SyntaxError: Unexpected token '??='

Error throw on start debuging sesson and exit. It seems that it happens because of node libary isn't compatible with the build file vsDebugServer.js. Is there have a specific requirement or I did it wrong?

[dap-js] JS Debugger stderr: /home/termux/.local/share/nvim/site/pack/packer/opt/vscode-js-debug/out/src/vsDebugServer.js:58
See: https://github.com/isaacs/node-glob/issues/167`);if(!... ar Tpe=require("path"),T8,$pe=()=>{if(process.platform==="win32")return T8??=D8(),T8},Mpe=t=>{var e;return(e=$pe())==null?void 0:e.getAppContainerProcessTokens().map(r=>(0,Tpe.joi
n)(r,t))};Lv.getAppContainerProcessTokens=Mpe});var Q8=b((QMe,Uv)=>{var jpe=require("fs"),Y8=require("path"),qpe=require("os"),Wpe=/(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\
s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/mg;function Vpe(t){let e={},r=t.toString();r=r.replace(/\r\n?/mg,`

SyntaxError: Unexpected token '??='
    at wrapSafe (internal/modules/cjs/loader.js:1029:16)
    at Module._compile (internal/modules/cjs/loader.js:1078:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1143:10)
    at Module.load (internal/modules/cjs/loader.js:979:32)
    at Function.Module._load (internal/modules/cjs/loader.js:819:12)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:75:12)
    at internal/main/run_main_module.js:17:47
Press ENTER or type command to continue
[dap-js] JS Debugger exited with code 1!

Here is my config file

require("dap-vscode-js").setup{
    node_path = "node", -- Path of node executable. vscode-js-debug require node verson 16
    adapters = { 'pwa-node', 'pwa-chrome', 'pwa-msedge', 'node-terminal', 'pwa-extensionHost' },
}

local dap = require('dap')
local js_languages = { "typescript", "javascript", "typescriptreact" }
for _, language in ipairs(js_languages) do
    dap.configurations[language] = {
        {
            type = "pwa-node",
            request = "launch",
            name = "Launch file",
            program = "${file}",
            cwd = "${workspaceFolder}",
        },
        {
            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

Support `startDebugging` request

The DAP spec has officially added support for multi-session debug adapters - microsoft/debug-adapter-protocol#344 🎉 🎉 🎉

According to @connor4312 in microsoft/vscode-js-debug#902 (comment):

Fyi this will soon be compliant with the adoption of microsoft/debug-adapter-protocol#79 this month, though DAP clients may take longer to update.

This plugin currently runs in a hacky/non-intended way, and my hope is that by adhering to a unified specification, issues like #14, #6, and #1 may be solved (fingers crossed). Even if they are not solved, it will be significantly easier to properly investigate these issues, as well as to determine if they are usage issues or just bugs in the vscode adapter.

The first goal is implementation into nvim-dap, which is slated for implementation. Then I can implement that into this plugin, which will (I think) significantly cut down on the required amount of code.

The second goal is perhaps to implement this hierarchy tree as part of nvim-dap-ui, assuming that the maintainers there are interested in such a feature.

Need Help.How to languch chrome in wsl

My environment is wsl2 and Ubuntu 20.04.4LTS
My neovim configuration is extened by LazyVim.And I want to debug React or Vue in neovim.

The error message is:"unable to find an installation of the browser on your system.Try installing it,or providing an absolute path to the browser in the 'runtimeExecutable' in your launch.json"

I think I have the right debugger_path.So I doubt it is a problem with wsl.But I can run the react project perfectly in the wsl2 and open the chrome directly by click the terminal website address when i run npm run dev.And i saw vscode-js-debug/blob/main/OPTIONS.md#browserlaunchlocation says

In a remote workspace (through ssh or WSL, for example) this can be used to open the browser on the remote machine rather than locally.

I don't know where the problem is?

Here is my configuration

 {
    "mxsdev/nvim-dap-vscode-js",
    event = "VeryLazy",
    dependencies = {
      "mfussenegger/nvim-dap",
      {
        "microsoft/vscode-js-debug",
        lazy = true,
        build = "npm install --legacy-peer-deps && npx gulp vsDebugServerBundle && mv dist out"
      }
    },
    config = function()
      local dap = require("dap")
      local dap_js = require("dap-vscode-js")
      -- vscode-js configuration for debugging support
      local DEBUG_PATH = vim.fn.stdpath("data") .. "/lazy/vscode-js-debug"
      dap_js.setup({
        node_path = "node",
        debugger_path = DEBUG_PATH,
        adapters = { "pwa-node", "node-terminal", "pwa-chrome" }, -- which adapters to register in nvim-dap
      })
      for _, language in ipairs({ "typescript", "javascript", }) do
        dap.configurations[language] = {
          {
            type = "pwa-node",
            request = "launch",
            name = "launch file (" .. language .. ")",
            program = "${file}",
            cwd = "${workspacefolder}",
          },
          {
            type = "pwa-node",
            request = "attach",
            name = "attach (" .. language .. ")",
            processid = require("dap.utils").pick_process,
            cwd = "${workspacefolder}",
          }
        }
      end
      for _, language in ipairs { "typescriptreact", "javascriptreact" } do
        require("dap").configurations[language] = {
          {
            type = "pwa-chrome",
            name = "Attach - Remote Debugging",
            request = "attach",
            program = "${file}",
            cwd = vim.fn.getcwd(),
            sourceMaps = true,
            protocol = "inspector",
            port = 9222,
            webRoot = "${workspaceFolder}",
          },
          {
            type = "pwa-chrome",
            name = "Launch Chrome",
            request = "launch",
            url = "http://localhost:3005",
            browserLaunchLocation = "workspace",
          },
        }
      end
    end
  },

Need help

I have the following config:

local dap = require('dap')
require('dap-vscode-js').setup {
    node_path = 'node',
    debugger_path = os.getenv('HOME') .. '/.local/share/nvim/mason/packages/js-debug-adapter',
    adapters = { 'pwa-node' },
}
for _, language in ipairs { 'typescript', 'javascript' } do
    dap.configurations[language] = {
        {
            type = 'pwa-node',
            request = 'launch',
            name = 'Launch file',
            program = '${file}',
            cwd = '${workspaceFolder}',
        },
        {
            type = 'pwa-node',
            request = 'attach',
            name = 'Attach',
            processId = require('dap.utils').pick_process,
            cwd = '${workspaceFolder}',
        },
        {
            type = 'pwa-node',
            request = 'launch',
            name = 'Debug Jest Tests',
            -- trace = true, -- include debugger info
            runtimeExecutable = 'node',
            runtimeArgs = {
                './node_modules/jest/bin/jest.js',
                '--runInBand',
            },
            rootPath = '${workspaceFolder}',
            cwd = '${workspaceFolder}',
            console = 'integratedTerminal',
            internalConsoleOptions = 'neverOpen',
        },
    }
end

When I launch the debugger, Dap gives this error:

Could not read source map for file:///home/troysigx/.local/share/nvim/mason/packages/js-debug-adapter/out/src/targets/out/src/common/cancellation.js: ENOENT: no such file or directory, open '/home/troysigx/.local/share/nvim/mason/packages/js-debug-adapter/out/src/targets/out/src/common/cancellation.js.map'
Could not read source map for file:///home/troysigx/.local/share/nvim/mason/packages/js-debug-adapter/out/src/targets/out/src/common/events.js: ENOENT: no such file or directory, open '/home/troysigx/.local/share/nvim/mason/packages/js-debug-adapter/out/src/targets/out/src/common/events.js.map'
Could not read source map for file:///home/troysigx/.local/share/nvim/mason/packages/js-debug-adapter/out/src/targets/out/src/common/findOpenPort.js: ENOENT: no such file or directory, open '/home/troysigx/.local/share/nvim/mason/packages/js-debug-adapter/out/src/targets/out/src/common/findOpenPort.js.map'
Could not read source map for file:///home/troysigx/.local/share/nvim/mason/packages/js-debug-adapter/out/src/targets/out/src/common/findOpenPortSync.js: ENOENT: no such file or directory, open '/home/troysigx/.local/share/nvim/mason/packages/js-debug-adapter/out/src/targets/out/src/common/findOpenPortSync.js.map'
Could not read source map for file:///home/troysigx/.local/share/nvim/mason/packages/js-debug-adapter/out/src/targets/out/src/common/knownTools.js: ENOENT: no such file or directory, open '/home/troysigx/.local/share/nvim/mason/packages/js-debug-adapter/out/src/targets/out/src/common/knownTools.js.map'
Could not read source map for file:///home/troysigx/.local/share/nvim/mason/packages/js-debug-adapter/out/src/targets/out/src/common/objUtils.js: ENOENT: no such file or directory, open '/home/troysigx/.local/share/nvim/mason/packages/js-debug-adapter/out/src/targets/out/src/common/objUtils.js.map'
Could not read source map for file:///home/troysigx/.local/share/nvim/mason/packages/js-debug-adapter/out/src/targets/out/src/common/promiseUtil.js: ENOENT: no such file or directory, open '/home/troysigx/.local/share/nvim/mason/packages/js-debug-adapter/out/src/targets/out/src/common/promiseUtil.js.map'
Could not read source map for file:///home/troysigx/.local/share/nvim/mason/packages/js-debug-adapter/out/src/targets/out/src/common/random.js: ENOENT: no such file or directory, open '/home/troysigx/.local/share/nvim/mason/packages/js-debug-adapter/out/src/targets/out/src/common/random.js.map'
Could not read source map for file:///home/troysigx/.local/share/nvim/mason/packages/js-debug-adapter/out/src/targets/out/src/dap/protocolError.js: ENOENT: no such file or directory, open '/home/troysigx/.local/share/nvim/mason/packages/js-debug-adapter/out/src/targets/out/src/dap/protocolError.js.map'
Could not read source map for file:///home/troysigx/.local/share/nvim/mason/packages/js-debug-adapter/out/src/targets/out/src/targets/node/bootloader.js: ENOENT: no such file or directory, open '/home/troysigx/.local/share/nvim/mason/packages/js-debug-adapter/out/src/targets/out/src/targets/node/bootloader.js.map'
Could not read source map for file:///home/troysigx/.local/share/nvim/mason/packages/js-debug-adapter/out/src/targets/out/src/targets/node/bootloader/environment.js: ENOENT: no such file or directory, open '/home/troysigx/.local/share/nvim/mason/packages/js-debug-adapter/out/src/targets/out/src/targets/node/bootloader/environment.js.map'
Could not read source map for file:///home/troysigx/.local/share/nvim/mason/packages/js-debug-adapter/out/src/targets/out/src/targets/node/bootloader/filters.js: ENOENT: no such file or directory, open '/home/troysigx/.local/share/nvim/mason/packages/js-debug-adapter/out/src/targets/out/src/targets/node/bootloader/filters.js.map'
Could not read source map for file:///home/troysigx/.local/share/nvim/mason/packages/js-debug-adapter/out/src/targets/out/src/targets/node/bootloader/logger.js: ENOENT: no such file or directory, open '/home/troysigx/.local/share/nvim/mason/packages/js-debug-adapter/out/src/targets/out/src/targets/node/bootloader/logger.js.map'
Could not read source map for file:///home/troysigx/.local/share/nvim/mason/packages/js-debug-adapter/out/src/targets/out/src/targets/node/bundlePaths.js: ENOENT: no such file or directory, open '/home/troysigx/.local/share/nvim/mason/packages/js-debug-adapter/out/src/targets/out/src/targets/node/bundlePaths.js.map'
Could not read source map for file:///home/troysigx/.local/share/nvim/mason/packages/js-debug-adapter/out/src/targets/out/src/targets/node/createTargetId.js: ENOENT: no such file or directory, open '/home/troysigx/.local/share/nvim/mason/packages/js-debug-adapter/out/src/targets/out/src/targets/node/createTargetId.js.map'
Could not read source map for file:///home/troysigx/.local/share/nvim/mason/packages/js-debug-adapter/out/src/targets/out/src/targets/node/lease-file.js: ENOENT: no such file or directory, open '/home/troysigx/.local/share/nvim/mason/packages/js-debug-adapter/out/src/targets/out/src/targets/node/lease-file.js.map'
Uncaught TypeError TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for /mnt/HDD/umass/umass-projects/cs220/03-more-image-processing-with-hof/src/moreImageProcessing.ts
    at __node_internal_captureLargerStackTrace (internal/errors:490:5)
    at NodeError (internal/errors:399:5)
    at getFileProtocolModuleFormat (internal/modules/esm/get_format:74:9)
    at defaultGetFormat (internal/modules/esm/get_format:114:38)
    at defaultLoad (internal/modules/esm/load:81:20)
    at nextLoad (internal/modules/esm/loader:163:28)
    at load (internal/modules/esm/loader:597:26)
    at moduleProvider (internal/modules/esm/loader:449:22)
    at ModuleJob (internal/modules/esm/module_job:63:26)
    at #createModuleJob (internal/modules/esm/loader:472:17)
    at getModuleJob (internal/modules/esm/loader:426:34)
    at processTicksAndRejections (internal/process/task_queues:95:5)
    --- await ---
    at processTicksAndRejections (internal/process/task_queues:95:5)
    --- await ---
    at runMainESM (internal/modules/run_main:53:21)
    at executeUserEntryPoint (internal/modules/run_main:79:5)
    at <anonymous> (internal/main/run_main_module:23:47)

I am using vscode-js-debug 1.76.0

pwa-node config for nestjs projects

Hello
I would like to know how I can configure correctly the adapter in order to get work the debugger?.
This is my current config

{
			type = "pwa-node",
			request = "launch",
			name = "NestJS: Launch",
			-- runtimeExecutable = "nest",
			program = "${workspaceFolder}/src/main.ts",
			cwd = "${workspaceFolder}",
			skipFiles = {
				"<node_internals>/**",
			},
			sourceMaps = true,
			resolveSourceMapLocations = {
				"${workspaceFolder}/**",
				"!**/node_modules/**",
			},
			protocol = "inspector",
			console = "integratedTerminal",
			port = 3000,
			-- args = { "start", "--watch", "--debug" },
			env = {
				NODE_ENV = "dev",
			},
			outFiles = {
				"${workspaceFolder}/dist/main.js",
			},
			sourceMapPathOverrides = {
				["webpack:///./src/*"] = "${workspaceFolder}/src/*",
				["webpack:///src/*"] = "${workspaceFolder}/src/*",
				["webpack:///*"] = "*",
			},
		},

With this config I get an error in the repl following the debug disconnect when Im trying to lunch the debug
Screenshot 2023-04-07 at 8 05 04 PM

And this is my tsconfig.js

image

thanks for the help in advance.

How to debug in an externalTerminal?

Hello

The issue I'm having is that the debugger does not attach when I set console to externalTerminal in the launch config.

my goal is to be able to see the logs of a debugged node.js app on a tmux pane. I use nodemon to start the server.

The initial approach I went for was to attach a debugger to a running nodemon process (i tried to attach to other node processes too), however, the debugger is not able to reattach to the app despite having the restart set to true on the launch config.

The next approach I tried was to launch the app directly from DAP. To my luck, the debugger attaches to all relevant node process to debug the app, as well as re-attach itself every time the server restarts.

Finally, I tried to look for ways to have the console output displayed at an external terminal. I was able to launch the app but the debugger isn't able to automatically attach to it

Please feel free to correct any terminologies I used incorrectly. I'm quite new in setting up nvim and dap configs

Below is an except of my config

require("dap").defaults.fallback.external_terminal = {
	command = "tmux",
	args = { "split-pane", "-h" }
}

local DEBUGGER_PATH = '/home/xxx/.local/share/nvim/lazy/vscode-js-debug'
...
        for _, language in ipairs { "typescript", "javascript" } do
            require("dap").configurations[language] = {
                {
                    type = "pwa-node",
                    request = "attach",
                    name = "Attach to process", -- works but disconnects every server restart. needs manual reconnection
                    processId = require("dap.utils").pick_process,
                    rootPath = "${workspaceFolder}",
                    cwd = "${workspaceFolder}",
                    restart = true,
                },
                {
                    type = "pwa-node",
                    request = "launch",
                    name = "npm run dev-debug (external)", -- doesn't attach to app
                    -- trace = true, -- include debugger info
                    runtimeExecutable = "npm",
                    runtimeArgs = {
                        "run",
                        "dev-debug",
                    },
                    rootPath = "${workspaceFolder}",
                    cwd = "${workspaceFolder}",
                    console = "externalTerminal",
                    internalConsoleOptions = "neverOpen",
                },
                {
                    type = "pwa-node",
                    request = "launch",
                    name = "npm run dev-debug (console)", -- works flawlessly
                    -- trace = true, -- include debugger info
                    runtimeExecutable = "npm",
                    runtimeArgs = {
                        "run",
                        "dev-debug",
                    },
                    rootPath = "${workspaceFolder}",
                    cwd = "${workspaceFolder}",
                    console = "integratedTerminal",
                    internalConsoleOptions = "neverOpen",
                },
            }
        end

Migrate config towards selecting server script path, rather than root directory

The vscode-js-debug recently switched folder structure from building to out to building to dist.

This breaks the codebase since I (in retrospect, rather stupidly) hard-coded the out/src/vsDebugServer.js path. Probably, the configuration for debugger_path should be to the script rather than the parent folder.

I don't wanna break existing installations, so probably it's best to add a config like debugger_script_path and try to phase out the old debugger_path.

Implement event_breakpoint in nvim-dap

Unlike many other dap based adapters, vscode-js-debug always communicates breakpoints as initially unverified (rejected), until this is changed layer with the breakpoint event. This is in order to support multiple child sessions, where the rejection status of a breakpoint may not be known until much after the initial setBreakpoints request.

This plugin currently "solves" this problem by hijacking the nvim-dap event loop and setting all breakpoints as initially verified, and then rechecking the status once a continued event is received. This solution is hacky and probably has some edge cases (particularly when there are multiple child sessions of interest).

This is essentially an issue with nvim-dap, so a parallel PR over there will be made eventually. I am cross-posting this here for the sake of tracking the issue.

Support for attaching to debugger listening on websocket connection

Been trying to get this working by spinning up a node process with the --inspect-brk flag.

Debugger listening on ws://127.0.0.1:9229/133fb593-50c7-4e71-b9fb-7269906ca972
For help, see: https://nodejs.org/en/docs/inspector

I noticed that when running the debugger in Neovim I get the error message

[dap-js] JS Debugger stderr: Error: Could not connect to debug target at http://127.0.0.1:9222: Could not find any debuggable target

Notice the http in the debug target. Is there some way to point at the websocket connection above?

Thanks!

nvim-dap stackTrace callback sometimes fails to launch

Under certain circumstances, the stackTrace callback in nvim-dap fails to launch.

Currently, this bug has only been produced by @entropitor, and may be related to jest configuration/version. See #2 for more details.

The first priority here is of course a minimal reproducible example, but any other info is still helpful!

vscode-js-debug build process has changed causing errors on fresh install

Just spent about 2 hours trying to get nvim-dap-vscode-js up and running but kept running into an error after installing and compiling says that /out/src/vsDebugServer.js couldn't be found. Again this was after npm install & compiling several times.

Finally checked out the gulp.js file for vscode-js-debug and the build process has recently changed. If anyone tries to follow the readme for this plugin now they'll fail just because the build process was switched out.

The temp fix for this is to set vscode-js-debug to a working commit-hash with whatever plugin installer you're using. I believe the one from Feb 24th works still.

Cannot start adapter: port is undefined

I tried to launch a debug session on the current file with the provided config:

local dap = require("dap")

-- Languages
require("dap-vscode-js").setup({
  -- node_path = "node", -- Path of node executable. Defaults to $NODE_PATH, and then "node"
  -- debugger_path = "(runtimedir)/site/pack/packer/opt/vscode-js-debug", -- Path to vscode-js-debug installation.
  -- 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' }, -- which adapters to register in nvim-dap
  -- log_file_path = "(stdpath cache)/dap_vscode_js.log" -- Path for file logging
  -- log_file_level = false -- Logging level for output to file. Set to false to disable file logging.
  -- log_console_level = vim.log.levels.ERROR -- Logging level for output to console. Set to false to disable console output.
})

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

When starting a new session I got :

[dap-js] JS Debugger stderr:
[dap-js] JS Debugger stderr: /home/jbrichardet/.local/share/nvim/site/pack/packer/opt/vscode-js-debug/src/vsDebugServer.ts:93                                                                                                                 
    console.log((result.server.address() as net.AddressInfo).port.toString());                                                                                                                                                                
                                                                 ^                                                                                                                                                                            
TypeError: Cannot read properties of undefined (reading 'toString')                                                                                                                                                                           
    at VsDebugServer.launchRoot (/home/jbrichardet/.local/share/nvim/site/pack/packer/opt/vscode-js-debug/src/vsDebugServer.ts:93:66)                                                                                                         
    at processTicksAndRejections (node:internal/process/task_queues:95:5)     
[dap-js] JS Debugger exited with code 1! 

I tried to look for a port to set but I did not find any in the adapter config or the configuration. Did I miss something ?

Thank you

DAP quits without stopping on breakpoint when running on typescript code

Hello, I am trying to debug a typescript file, test.ts:

const x = 1;
const y = 2;
const z: number = 3;
console.log(x, y, z);
console.log('Test');

When I try to run the debugger on the above file, with a breakpoint on the last line, it starts and then quits immediately, without any sort of error. I have tried looking in dap-vscode-js logs, and dap logs, but can't find anything.

Interestingly, when I run the below code, almost the same as above except without type information, it works fine and stops on the breakpoint:

const x = 1;
const y = 2;
const z = 3;
console.log(x, y, z);
console.log('Test');

Here are my relevant neovim config lines:

require("dap-vscode-js").setup({
  adapters = { 'pwa-node', 'pwa-chrome', 'pwa-msedge', 'node-terminal', 'pwa-extensionHost' }, -- which adapters to register in nvim-dap
  log_file_path = "/tmp/dap_vscode_js.log",
  log_file_level = vim.log.levels.DEBUG,
  log_console_level = vim.log.levels.DEBUG,
})

...

use { "mxsdev/nvim-dap-vscode-js", requires = {"mfussenegger/nvim-dap"} }
use {
  "microsoft/vscode-js-debug",
  opt = true,
  run = "npm install --legacy-peer-deps && npm run compile",
}

...

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

Can someone please help?

[Process Exit 0]

Trying to debug a node.js typescript api, as soon as i set a breakpoint and continue. dap exits with Process Exit 0

image

config


nnoremap <silent> <F5> <Cmd>lua require'dap'.continue()<CR>
nnoremap <silent> <F10> <Cmd>lua require'dap'.step_over()<CR>
nnoremap <silent> <F11> <Cmd>lua require'dap'.step_into()<CR>
nnoremap <silent> <F12> <Cmd>lua require'dap'.step_out()<CR>
nnoremap <silent> <Leader>b <Cmd>lua require'dap'.toggle_breakpoint()<CR>
nnoremap <silent> <Leader>B <Cmd>lua require'dap'.set_breakpoint(vim.fn.input('Breakpoint condition: '))<CR>
nnoremap <silent> <Leader>lp <Cmd>lua require'dap'.set_breakpoint(nil, nil, vim.fn.input('Log point message: '))<CR>
nnoremap <silent> <Leader>dr <Cmd>lua require'dap'.repl.open()<CR>
nnoremap <silent> <Leader>dl <Cmd>lua require'dap'.run_last()<CR>

lua <<EOF

-- require("dapui").setup()

local dap, dapui = require("dap"), require("dapui")

dap.set_log_level('TRACE')
dap.listeners.after.event_initialized["dapui_config"] = function()
  dapui.open()
end
dap.listeners.before.event_terminated["dapui_config"] = function()
  dapui.close()
end
dap.listeners.before.event_exited["dapui_config"] = function()
  dapui.close()
end

require("dap-vscode-js").setup({
  -- node_path = "node", -- Path of node executable. Defaults to $NODE_PATH, and then "node"
  debugger_path = "/home/kay/vscode-js-debug", -- Path to vscode-js-debug installation.
  -- 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' }, -- which adapters to register in nvim-dap
  -- log_file_path = "(stdpath cache)/dap_vscode_js.log" -- Path for file logging
  -- log_file_level = false -- Logging level for output to file. Set to false to disable file logging.
  -- log_console_level = vim.log.levels.ERROR -- Logging level for output to console. Set to false to disable console output.
})

for _, language in ipairs({ "typescript", "javascript" }) do
  dap.configurations[language] = {
  {
    type = "pwa-node",
    request = "launch",
    name = "Launch file",
    program = "${file}",
    cwd = "${workspaceFolder}",
	protocol = "inspector",
	console = "integratedTerminal",
	runtimeExecutable = "${workspaceFolder}/node_modules/.bin/ts-node",
    resolveSourceMapLocations = { "${workspaceFolder}/dist/**/*.js", "${workspaceFolder}/**", "!**/node_modules/**" },
    skipFiles = { "<node_internals>/**", "**/node_modules/**" },
    port = 9229,
    sourceMaps = true
  },
  {
    type = "pwa-node",
    request = "attach",
    name = "Attach",
    processId = require'dap.utils'.pick_process,
    cwd = "${workspaceFolder}",
  }
}
end


EOF

Debug adapter disconnected

When I try to run this command :lua require'dap'.continue() with the config below I get a message: "Debug adapter disconnected"
my js-dap.lua file

require("dap-vscode-js").setup({
	-- node_path = "node", -- Path of node executable. Defaults to $NODE_PATH, and then "node"
	-- debugger_path = "(runtimedir)/site/pack/packer/opt/vscode-js-debug", -- Path to vscode-js-debug installation.
	--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" }, -- which adapters to register in nvim-dap
	-- log_file_path = "(stdpath cache)/dap_vscode_js.log" -- Path for file logging
	-- log_file_level = false -- Logging level for output to file. Set to false to disable file logging.
	-- log_console_level = vim.log.levels.ERROR -- Logging level for output to console. Set to false to disable console output.
})
for _, language in ipairs({ "typescript", "javascript" }) do
	require("dap").configurations[language] = {
		{
			type = "pwa-node",
			request = "launch",
			name = "Launch file",
			program = "${file}",
			cwd = "${workspaceFolder}",
		},
	}
end

my packer.lua:

	use({ "mxsdev/nvim-dap-vscode-js", requires = { "mfussenegger/nvim-dap" } })
	use({
		"microsoft/vscode-js-debug",
		opt = true,
		run = "npm install --legacy-peer-deps && npx gulp vsDebugServerBundle && mv dist out",
	})
	use("rcarriga/nvim-dap-ui")

i also downloaded js-debug-adapter using Mason but it didn't help

Unable to debug worker threads

I'm trying to debug with worker threads. When it hits a breakpoint (DapStopped sign shows up), I can't continue, step over, inspect a variable, etc. It acts as it doesn't know it hit a breakpoint. When I do :lua require'dap'.continue() to continue, it gives me

Session active, but not stopped at breakpoint

And when I do :lua require'dap.ui.widgets'.hover() to inspect a variable, it gives me

Cannot evaluate "foo"!

Below is my config for javascript. It works perfectly without worker threads. And it also works in VS Code with worker threads (with "type": "node").

{
  type = 'pwa-node',
  request = 'launch',
  name = 'Debug',
  program = '${file}',
  cwd = '${fileDirname}',
  sourceMaps = true,
  skipFiles = { '<node_internals>/**' },
  outputCapture = 'std',
  resolveSourceMapLocations = {
    '**',
    '!**/node_modules/**',
  },
},

Is this a bug or misconfiguration?

Why the `pwa-` prefixes?

I noticed that nvim-dap-vscode-js doesn't work for launch.json tasks that don't have the "task" value prefixed with pwa- (like "pwa-node"). According to microsoft/vscode-js-debug#1404, pwa- should no longer be used. Are there any plans to remove the pwa- prefixes for nvim-dap-vscode-js and/or also support launch.json files with just "node", "chrome", etc.?

Debug Attaching seems like it is trying to start it's own server [EADDRINUSE]

I can't seem to connect the debug adapter to my local running node service. My config looks like:

    config = function()
      local dap = require "dap"
      local attach_node = {
        type = "pwa-node",
        name = "Attach to Node",
        request = "attach",
        address = "127.0.0.1",
        processId = require("dap.utils").pick_process,
        cwd = "${workspaceFolder}",
      }

      dap.adapters["pwa-node"] = {
        type = "server",
        host = "localhost",
        port = "9229",
        executable = {
          command = "js-debug-adapter",
          args = { "9229" },
        },
      }

      dap.configurations.javascript = {
        attach_node,
      }
      dap.configurations.typescript = {
        attach_node,
      }
    end,
  }

However when I start my service manually and try to connect using that attatch_node configuration, I get this error from the debug-adapter

[debug-adapter stderr] Error: listen EADDRINUSE: address already in use 127.0.0.1:9229
    at Server.setupListenHandle [as _listen2] (node:net:1463:16)
    at listenInCluster (node:net:1511:12)
    at GetAddrInfoReqWrap.doListen [as callback] (node:net:1660:7)
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:111:8) {
  code: 'EADDRINUSE',
  errno: -48,
  syscall: 'listen',
  address: '127.0.0.1',
  port: 9229
}

Which makes me think, the debug adapter is also trying to start it's own instance even though it should just be attaching to the already running instance. Any help would be greatly appreciated.

Debugger don't work with imports/packages

When I debug a code without importing none of it works normally.
image

But when there is an import it doesn't work. It opens the UI but ends soon after.
image

My plugins.lua

{
    "mfussenegger/nvim-dap",
    config = function()
      require "custom.configs.dap"
      require("core.utils").load_mappings "dap"
    end,
  },

  {
    "rcarriga/nvim-dap-ui",
    event = "VeryLazy",
    dependencies = "mfussenegger/nvim-dap",
    config = function()
      local dap = require "dap"
      local dapui = require "dapui"
      dapui.setup()
      dap.listeners.after.event_initialized["dapui_config"] = function()
        dapui.open()
      end
      dap.listeners.before.event_terminated["dapui_config"] = function()
        dapui.close()
      end
      dap.listeners.before.event_exited["dapui_config"] = function()
        dapui.close()
      end
    end,
  },
  {
    "mxsdev/nvim-dap-vscode-js",
    dependencies = "mfussenegger/nvim-dap",
    ft = { "javascript", "typescript" },
  },

My configs dap.config

local dap = require "dap"

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

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

'$HOME/vscode-js-debug/out/src/vsDebugServer.js' does not exist. Did it build properly?

i have vscode-js-debug installed in my home directory. I ran npm install --legacy-peer-deps && npm run compile without any issues.

  1. i set a break up in my code.
  2. Run F5 and launch (1)
  3. Get the following error:

[dap-js] Error trying to launch JS debugger: ...m/plugged/nvim-dap-vscode-js/lua/dap-vscode-js/utils.lua:64: Debugger
entrypoint file '$HOME/vscode-js-debug/out/src/vsDebugServer.js' does not exist. Did it build properly?

Screenshot from 2022-11-18 13-37-40

dap.vim

nnoremap <silent> <F5> <Cmd>lua require'dap'.continue()<CR>
nnoremap <silent> <F10> <Cmd>lua require'dap'.step_over()<CR>
nnoremap <silent> <F11> <Cmd>lua require'dap'.step_into()<CR>
nnoremap <silent> <F12> <Cmd>lua require'dap'.step_out()<CR>
nnoremap <silent> <Leader>b <Cmd>lua require'dap'.toggle_breakpoint()<CR>
nnoremap <silent> <Leader>B <Cmd>lua require'dap'.set_breakpoint(vim.fn.input('Breakpoint condition: '))<CR>
nnoremap <silent> <Leader>lp <Cmd>lua require'dap'.set_breakpoint(nil, nil, vim.fn.input('Log point message: '))<CR>
nnoremap <silent> <Leader>dr <Cmd>lua require'dap'.repl.open()<CR>
nnoremap <silent> <Leader>dl <Cmd>lua require'dap'.run_last()<CR>


lua <<EOF

local dap, dapui = require("dap"), require("dapui")
dap.listeners.after.event_initialized["dapui_config"] = function()
  dapui.open()
end
dap.listeners.before.event_terminated["dapui_config"] = function()
  dapui.close()
end
dap.listeners.before.event_exited["dapui_config"] = function()
  dapui.close()
end

require("dap-vscode-js").setup({
  -- node_path = "node", -- Path of node executable. Defaults to $NODE_PATH, and then "node"
  debugger_path = "$HOME/vscode-js-debug", -- Path to vscode-js-debug installation.
  -- 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' }, -- which adapters to register in nvim-dap
  log_file_path = "(stdpath cache)/dap_vscode_js.log", -- Path for file logging
  -- log_file_level = true, -- Logging level for output to file. Set to false to disable file logging.
  log_console_level = vim.log.levels.ERROR, -- Logging level for output to console. Set to false to disable console output.
})

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


EOF

Couldn't connect to localhost:${port}: ECONNREFUSED

I can't get this plugin to work. After calling require('dap').continue() I get the error Couldn't connect to localhost:${port}: ECONNREFUSED. Below is the minimal config that I'm using:

Click to expand
local root = vim.fn.fnamemodify(vim.fn.expand('$HOME') .. '/code-other/nvim-test-config', ':p')

-- set stdpaths to use .repro
for _, name in ipairs({ 'config', 'data', 'state', 'cache' }) do
  vim.env[('XDG_%s_HOME'):format(name:upper())] = root .. '/' .. name
end

-- bootstrap lazy
local lazypath = root .. '/plugins/lazy.nvim'
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system({ 'git', 'clone', '--filter=blob:none', 'https://github.com/folke/lazy.nvim.git', lazypath, })
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
  { 'williamboman/mason.nvim', config = true },
  {
    'mfussenegger/nvim-dap',
    dependencies = { 'mxsdev/nvim-dap-vscode-js' },
    config = function()
      local dap = require('dap')

      require('dap-vscode-js').setup({
        debugger_path = require('mason-registry').get_package('js-debug-adapter'):get_install_path(),
        debugger_cmd = { 'js-debug-adapter' },
        adapters = {
          'pwa-node',
          'pwa-chrome',
          'pwa-msedge',
          'node-terminal',
          'pwa-extensionHost',
        },
      })

      dap.adapters['pwa-node'] = {
        type = 'server',
        host = 'localhost',
        port = '${port}',
        executable = {
          command = 'js-debug-adapter',
          args = { '${port}' },
        }
      }

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


      vim.keymap.set('n', '<leader>db', dap.toggle_breakpoint)
      vim.keymap.set('n', '<leader>dc', dap.continue)
    end,
  }
}

vim.g.mapleader = ' '
vim.keymap.set('n', '<C-q>', '<cmd>qa<CR>')

require('lazy').setup(plugins, {
  root = root .. '/plugins',
})

Here's the TL;DR of the config, which is based on the installation instructions and this thread:

local dap = require('dap')

require('dap-vscode-js').setup({
  debugger_path = require('mason-registry').get_package('js-debug-adapter'):get_install_path(),
  debugger_cmd = { 'js-debug-adapter' },
  adapters = {
    'pwa-node',
    'pwa-chrome',
    'pwa-msedge',
    'node-terminal',
    'pwa-extensionHost',
  },
})

dap.adapters['pwa-node'] = {
  type = 'server',
  host = 'localhost',
  port = '${port}',
  executable = {
    command = 'js-debug-adapter',
    args = { '${port}' },
  }
}

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

You should be able to download and launch the config above with nvim -u /path/to/file/above.

Steps to reproduce:

  1. nvim -u /path/to/file/above test.ts
  2. Press <space>dc (to start debugging)
  3. After a few seconds, the message Couldn't connect to localhost:${port}: ECONNREFUSED appears

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

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.