nvim-dap icon indicating copy to clipboard operation
nvim-dap copied to clipboard

[Typescript] Cannot debug projects with ES Modules (works with CommonJS)

Open Lap1n opened this issue 7 months ago • 2 comments

Debug adapter definition and debug configuration

        dap.adapters["pwa-node"] = {
          type = "server",
          host = "localhost",
          port = "${port}",
          executable = {
            command = js_debug_bin,
            args = { "${port}" },
          },
          options = {
            detached = false,
          },
          enrich_config = function(config, on_config)
            -- Under the hood, always use the main adapter
            config.type = "pwa-node"
            on_config(config)
          end,
        }

Launch.json config:

    {
      "name": "Attach to node Process",
      "type": "node",
      "request": "attach",
      "port": 9229,
      "skipFiles": [
        "<node_internals>/**"
      ],
      "sourceMaps": true
    },

Debug adapter version

v1.104.0

Steps to Reproduce

  1. In a Node ESM TypeScript project where stack frames reference sources as relative paths (e.g., “../src/foo.ts”).
  2. Set breakpoints in a “src/*” file before attaching.
  3. Attach to the running process with the config above, continue to a point that should hit the breakpoint.

Expected Result

  • Breakpoints bind immediately and the editor shows the local workspace file content.

Actual Result

  • Breakpoints works
  • The launch.json config works in VS code

Lap1n avatar Sep 27 '25 19:09 Lap1n

I vibe coded a fix for this, but not comfortable enough (yet) with the DAP protocol to open a PR .

In short, it seems like registering breakpoints with ESM project requires a different flow than the normal one and relies on source reference instead of just source.path.

The impl. is accessible here.

Lap1n avatar Sep 27 '25 19:09 Lap1n

Can you post logs and a complete but minimal reproduction?

mfussenegger avatar Oct 25 '25 05:10 mfussenegger

Closing due to lack of feedback and given that I suspect this is either a debug adapter problem or configuration issue, not a client bug.

mfussenegger avatar Jan 05 '26 10:01 mfussenegger