Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

json - 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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...