8

On my Ubuntu 16.04 I use IntelliJ IDEA ultima 2017.2 together with node v6.11.2 and npm v3.10.10 and want to debug a node.js application, which has the following package.json start entry:

"start:" "npm-run-all --parallel serve-static open-static"

According to the console output and this similar SO question I need to add $NODE_DEBUG_OPTION as first parameter (for node) to avoid the Connection refused error. Obvioulsy, I have tried

  • to add $NODE_DEBUG_OPTION in the Run/Debug configuration as Arguments
  • and as Node options

which resulted in calls like

node npm-cli.js run start-debug --scripts-prepend-node-path=auto $NODE_DEBUG_OPTION

and

node $NODE_DEBUG_OPTION npm-cli.js run start-debug --scripts-prepend-node-path=auto 

in each case $NODE_DEBUG_OPTION is not resolved and node treats it like a non-existing file.

I have also tried to add variable directly in package.json like

    "start:" "npm-run-all $NODE_DEBUG_OPTION --parallel serve-static open-static"

which also results in a Cannot find module .../$NODE_DEBUG_OPTION error.

So, how can I pass this option in order to debug that thingy in IntelliJ IDEA?

Thanks

x y
  • 911
  • 9
  • 27

2 Answers2

8

adding $NODE_DEBUG_OPTION to package.json manually is the only way to debug the application started via npm script, because you have to make sure that Node.js is started with appropriate debug options (--debug-brk, --inspect-brk, etc), and the IDE can't control the way child processes are spawned - it can only pass options to the main process when starting it. But this option has to be passed to Node.js - not to npm-cli.js, npm-run-all, etc. If npm-run-all is an npm script that starts the app you'd like to debug with node.js, you need to modify this script accordingly, like:

"npm-run-all": "node $NODE_DEBUG_OPTION myapp.js" 

If your task runs a shell script, that, in turn, runs your app with node.js, you need to modify a shell script... The goal is to start the node process with debug options

lena
  • 90,154
  • 11
  • 145
  • 150
0

$NODE_DEBUG_OPTION has to be argument for nodeJs, before executing nodeJs script.

"some:task": "node $NODE_DEBUG_OPTION ./path/to/script.js" 

All plugins / dependencies are nodeJs scripts. You just need to find correct path, and run that CLI with node, not as standalone CLI.

In your case npm-run-all (as most of CLI) is located under node_modules/.bin/:

"start:" "node $NODE_DEBUG_OPTION ./node_modules/.bin/npm-run-all --parallel serve-static open-static"
lima_fil
  • 1,744
  • 27
  • 34