dape.el and attaching to Node process
By default, dape.el’s `dape-configs` variable includes the `js-debug-node` and `js-debug-chrome` configurations. See https://github.com/svaante/dape/blob/4694a7323b6bb6747f072c4c1253d18cf07a113f/dape.el#L196-L231
However, those are meant to start a file you’re currently in in debug mode.
If you prefer to start your Node process somewhere else using node --inspect [myfile.js], the above two configurations won’t work.
Thankfully, it’s easy to add such a configuration yourself - see (js-debug-attach ... at the bottom.
You can run it using M-x dape and typing in js-debug attach :port 9229. You have to provide the port because it’s not specified in the below `dape-configs` var, and dape allows you to add props before running a pre-made configuration.
Make sure to set up the debugger adapter package: https://github.com/svaante/dape?tab=readme-ov-file#javascript---vscode-js-
(setq
dape-configs `(
,@(let ((js-debug
`(modes (js-mode js-ts-mode typescript-mode typescript-ts-mode)
ensure ,(lambda (config)
(dape-ensure-command config)
(let ((js-debug-file
(file-name-concat
(dape--config-eval-value (plist-get config 'command-cwd))
(dape--config-eval-value (car (plist-get config 'command-args))))))
(unless (file-exists-p js-debug-file)
(user-error "File %S does not exist" js-debug-file))))
command "node"
command-args (,(expand-file-name
(file-name-concat dape-adapter-dir
"js-debug"
"src"
"dapDebugServer.js"))
:autoport)
port :autoport
fn dape-config-autoport)))
`((js-debug-node
,@js-debug
:type "pwa-node"
:cwd dape-cwd
:program dape-buffer-default
:outputCapture "console"
:sourceMapRenames t
:pauseForSourceMap nil
:autoAttachChildProcesses t
:console "internalConsole"
:killBehavior "forceful")
(js-debug-chrome
,@js-debug
:type "pwa-chrome"
:url "http://localhost:3000"
:webRoot dape-cwd
:outputCapture "console")
(js-debug-attach
,@js-debug
:request "attach"
:type "pwa-node")))
))
You may be weirded out by seeing the type: "pwa-node" instead of type: "node".
type: "node" was used in launch.json files in the old vscode js debugger that is now deprecated since Dec 15, 2022: https://github.com/microsoft/vscode-node-debug2
type: "pwa-node" is the new debug adapter protocol that the dape README.md is telling you to install, seen here: https://github.com/microsoft/vscode-js-debug