Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JS debugger not working #63

Open
vaibhav135 opened this issue Oct 26, 2023 · 3 comments
Open

JS debugger not working #63

vaibhav135 opened this issue Oct 26, 2023 · 3 comments

Comments

@vaibhav135
Copy link

vaibhav135 commented Oct 26, 2023

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
@eyescr3am
Copy link

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
Copy link

dseravalli commented Nov 15, 2023

{
  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)

@eyescr3am
Copy link

eyescr3am commented Nov 17, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants