Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get VSCode to attach to nodemon started by NPM?

Can I have VSCode kick off my app using NPM run scripts and then attach to the resulting process to debug?

My project kicks off with nodemon via NPM script (to execute babel, etc). However, while the app kicks off, VSCode's debugger doesn't attach (breakpoints are skipped).

// from package.json

"scripts": { "debug": "nodemon --inspect --exec babel-node src/app.js" }

// from launch.json

    {
      "type": "node",
      "request": "launch",
      "name": "Debug",
      "runtimeExecutable": "npm",
      "runtimeArgs": [
        "run-script",
        "debug"
      ],
      "address": "localhost",
      "port": 9229,
      "protocol": "auto",
      "restart": true,
      "console": "integratedTerminal",
      "internalConsoleOptions": "neverOpen",
      "autoAttachChildProcesses": true
    }

It seems the debugger starts but breakpoints I placed next to a few test calls are ignored. Here's the terminal output:

[nodemon] 1.19.1
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `babel-node --inspect src/app.js`
Debugger listening on ws://127.0.0.1:9229/13ef6ca8-40da-4741-854a-467e4230b2a7
For help, see: https://nodejs.org/en/docs/inspector
Debugger attached.
Hey!
Waiting for the debugger to disconnect...
[nodemon] clean exit - waiting for changes before restart```
like image 990
Mike Vittiglio Avatar asked Nov 07 '22 14:11

Mike Vittiglio


1 Answers

Looks like this was a fool's errand because it technically can't be done.

like image 71
Mike Vittiglio Avatar answered Nov 14 '22 20:11

Mike Vittiglio