mxsdev / nvim-dap-vscode-js

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

JS debugger not working #63

Open vaibhav135 opened 1 year ago

vaibhav135 commented 1 year ago

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
hansp27 commented 1 year ago

Here's how I made it work, although I should note I didn't use this extension.

local dap = require('dap')

dap.adapters["pwa-node"] = {
  type = "server",
  host = "localhost",
  port = "${port}", --let both ports be the same for now...
  executable = {
    command = "node",
    -- -- 💀 Make sure to update this path to point to your installation
    args = { vim.fn.stdpath('data') .. "/mason/packages/js-debug-adapter/js-debug/src/dapDebugServer.js", "${port}" },
    -- command = "js-debug-adapter",
    -- args = { "${port}" },
  },
}

for _, language in ipairs({ "typescript", "javascript" }) do
  dap.configurations[language] = {
    {
      type = 'pwa-node',
      request = 'launch',
      name = 'Launch Current File (pwa-node)',
      cwd = "${workspaceFolder}", -- vim.fn.getcwd(),
      args = { '${file}' },
      sourceMaps = true,
      protocol = 'inspector',
    },
    {
      type = 'pwa-node',
      request = 'launch',
      name = 'Launch Current File (Typescript)',
      cwd = "${workspaceFolder}",
      runtimeArgs = { '--loader=ts-node/esm' },
      program = "${file}",
      runtimeExecutable = 'node',
      -- args = { '${file}' },
      sourceMaps = true,
      protocol = 'inspector',
      outFiles = { "${workspaceFolder}/**/**/*", "!**/node_modules/**" },
      skipFiles = { '<node_internals>/**', 'node_modules/**' },
      resolveSourceMapLocations = {
        "${workspaceFolder}/**",
        "!**/node_modules/**",
      },
    },
  }
end
dseravalli commented 12 months ago
{
  type = 'pwa-node',
  request = 'launch',
  name = 'Launch Current File (Typescript)',
  cwd = "${workspaceFolder}",
  runtimeArgs = { '--loader=ts-node/esm' },
  program = "${file}",
  runtimeExecutable = 'node',
  -- args = { '${file}' },
  sourceMaps = true,
  protocol = 'inspector',
  outFiles = { "${workspaceFolder}/**/**/*", "!**/node_modules/**" },
  skipFiles = { '<node_internals>/**', 'node_modules/**' },
  resolveSourceMapLocations = {
    "${workspaceFolder}/**",
    "!**/node_modules/**",
  },
}

When I try this config, I get this error when I launch the debugger, even though ts-node is installed (via Homebrew on MacOS). It works if I install ts-node as a project dependency. Do you know if there is a way to configure the debugger to use the global ts-node?

Process exited with code 1
(node:43621) ExperimentalWarning: Custom ESM Loaders is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
Uncaught Error Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'ts-node' imported from /Users/danseravalli/Developer/personal/leetcode/3-longest-substring-without-repeating-characters/
    at __node_internal_captureLargerStackTrace (internal/errors:496:5)
    at NodeError (internal/errors:405:5)
    at packageResolve (internal/modules/esm/resolve:890:9)
    at moduleResolve (internal/modules/esm/resolve:939:20)
    at defaultResolve (internal/modules/esm/resolve:1132:11)
    at nextResolve (internal/modules/esm/loader:163:28)
    at resolve (internal/modules/esm/loader:835:30)
    at getModuleJob (internal/modules/esm/loader:424:18)
    at import (internal/modules/esm/loader:524:22)
    at loadModulesInIsolation (internal/process/esm_loader:92:34)
    at initializeLoader (internal/process/esm_loader:61:25)
    at loadESM (internal/process/esm_loader:101:11)
    at runMainESM (internal/modules/run_main:60:21)
    at executeUserEntryPoint (internal/modules/run_main:83:5)
    at <anonymous> (internal/main/run_main_module:23:47)
    --- await ---
    at runMainESM (internal/modules/run_main:60:21)
    at executeUserEntryPoint (internal/modules/run_main:83:5)
    at <anonymous> (internal/main/run_main_module:23:47)
hansp27 commented 11 months ago

For this config you need to install the ts-node package with npm/yarn/etc. Try sudo npm i -g ts-node