8

I would like to launch a bin command in debug mode. But I can't seem to write --inspect-brk=3000 as an argument as it only wants to accept a filename and npm link checks if file exists.

  "bin": {
    "mycommand": "index.js --inspect-brk=3000",
  }

ENOENT: no such file or directory

Any ideas? I might just make a debug.js that launches the index.js passing the arg and piping the stdin/stdout.

1 Answer 1

3

debug.js

#!/usr/bin/env node
// A wrapper to allow starting the index.js in debug mode port is 3000
const { spawn } = require('child_process')
var child = spawn('node', ['--inspect-brk=3000', 'index.js'], { stdio: 'inherit' })

launch.json

        {
            "type": "node",
            "request": "launch",
            "name": "Launch Program",
            "program": "",
            "runtimeExecutable": "${workspaceFolder}/../Tools/someprogramthatrunsmine",
            "runtimeArgs": [
                "mycommand-debug",
                "someinputs"
            ],
            "cwd": "${workspaceFolder}",
            //"console": "integratedTerminal",
            "port": 3000
        }
    ]

package.json bin command

  "bin": {
    "mycommand-debug": "debug.js"
  },

Run npm link to link the command for local testing.

Clicking the Debug button in Vscode can now breakpoint my index.js code when it is run by a different runtime executable.

Not the answer you're looking for? Browse other questions tagged or ask your own question.