Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IntelliJ IDEA how to correctly pass $NODE_DEBUG_OPTION to npm-run-all

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

like image 790
x y Avatar asked Aug 30 '17 17:08

x y


People also ask

How does npm run dev work?

The npm run dev command is a generic npm command that you can find in many modern web application projects. This command is used to run the dev script defined in the project's package. json file. To know what is exactly being run by the command, first you need to open the package.


1 Answers

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

like image 91
lena Avatar answered Nov 15 '22 10:11

lena