npm tasks debug in WebStorm

Continuing the “debug with the WebStorm” posts series. Previously I have shared my experience of having the Node.js remote debugging in WebStorm working. Today – I’m going to share with you my findings of how to make the debug of the npm task.

My goal was to debug the lab tests, which I use to test my hapi application.

Before I have started, the “scripts” part of my package.json file looked the next way:

I’ve tried to add the “Run/Debug Configuration” to the WebStorm, but when running it – nothing was happening. The tests were executed, however the application was not stopped on the debug points.

npm tasks debug WebStorm

npm tasks debug WebStorm

After some time I have figured out the correct formula, which I want to share with you, so you spend less time doing that. The key thing is your package.json file, here how it should look like:

There are three key factors:

  1. The task which you want to debug should be run by node, not by any other global program
  2. You need to place the $NODE_DEBUG_OPTION placeholder to the npm task, WebStorm will put there the debug configuration parameter
  3. If you haven’t done any additional configuration, WebStorm would not know where all the “global” programs are located. So you need to correctly point the source, which will be executed by your node instance. In my example I’ve stated the local version of lab.

Hope that saved someones time!

  • Ben Dean

    Having just encountered this issue myself ( I want to point out that this effect can be achieved without any edits to the run script or package.json at all. In the Run/Debug Configurations window of Webstorm, you can pass “$NODE_DEBUG_OPTiON” to the script in the Arguments field.

    • Joe Lane

      You mean “$NODE_DEBUG_OPTION” right?

  • Vitaly Kuzmich

    Useful guide, thx.

  • Lorenzo Jiménez

    And for Windows, you can use %NODE_DEBUG_OPTION%

  • dmbfk

    Thank you for this insight Pavel – excellent job. At the time of this post, July 2017, JetBrain’s own documentation on npm integration is very poor, lacking any kind of examples. Sure it has an abundance of configuration options but unfortunately somebody at JetBrain’s thinks doing a roll-call on every field in a config dialog and summarising them makes a coherent and useful manual which is just garbage. Thank you for saving me half a day wrestling with JetBrain’s inability to provide examples!