`Connection refused` in WebStorm NPM debug configuration

半腔热情 提交于 2019-12-01 02:25:11

The error message is indeed very unclear. You need to adjust your npm script entry in the package.json (sadly). Found a clear description in this blog post: http://pavelpolyakov.com/2016/05/01/webstorm-npm-tasks-debug/

Your start entry should look like the following:

"scripts": {
    "start": "node $NODE_DEBUG_OPTION ./node_modules/someModule/bin/someModule.js --arguments"
}

You could also go with two entries to keep the first one DRY. Though it is not really necessary since both run just fine from command line. So just for completeness' sake:

"scripts": {
    "start": "someModule --arguments",
    "startDebug": "node $NODE_DEBUG_OPTION ./node_modules/someModule/bin/someModule.js --arguments"
}

I don't find this method particularly clean, imo that is what the npm debugger should do for you without having to manipulate source code. But it appears to be the only way (for now).

I never needed this in previous versions of Node or Webstorm. Not sure which changed requiring this option now.

I had to add it in the package.json, though, adding it to the run configuration does not work. And I had to make a separate script because it broke when running any script without debugging.

Here's my package.json (Note Windows style variables %VAR%, use $VAR for Unix-like systems):

"scripts": {
    "start": "node index.js",
    "debug": "node %NODE_DEBUG_OPTION% index.js",
},

Then when I want to debug I use a run configuration that calls the debug option--because in Windows at least, node is taking the var literally when it's not replaced.


If you try to enter the variable in Webstorm's (2016.3.3) run configuration dialog:

It results in these actual commands, which are incorrect:

As a script argument:

"C:\...\runnerw.exe" "C:\...\node.exe" "C:\...\npm-cli.js" run start %NODE_DEBUG_OPTION%

As a Node option:

"C:\...\runnerw.exe" "C:\...\node.exe" %NODE_DEBUG_OPTION% "C:\...\npm-cli.js" run start

But the options seem to need to be passed to NPM, not the npm script (former), and not node (latter), and there's no way to do that in the dialog, as far as I know. Thus, adding to the package.json script command.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!