2019.3 Debugger fails (doesn't attach) with node --inspect-brk main.js.
Given:
- An application which uses npm package.json scripts to fire up nodejs application
- package.json scripts use node --inspect-brk dist/main.js to initiate nodejs with the debugger
When:
- I right click on the debug script in the npm tab in WebStorm
- And choose debug from the option
Then:
- The debugger should attach to the process and breakpoints should be hit.
Observed:
- The debugger starts a debug listener on *every* nodejs process invoked by the package.json script, not just the one containing "--inspect"
- That leaves me with 4 attached debuggers - but the debugger *never attaches* to the one I specified (running on 9229 by default)
- The application hangs waiting for the debugger to attach.
Analysis:
- Through trial and error my team determined that the debugger actually works now for our "normal" development script.
- It appears that 2019.3 made an improvement that enables us to debug node without any special package.json scripts. No need for --inspect
- ^-- This is great for all of us that use WebStorm, but...
- How would anyone know to do this?
- The command line is the source of truth for our app - it should work with *any IDE*. now we have to test the debug script outside of webstorm to make sure it still works.
TLDR: The debug option should work with package.json scripts that rely on --inspect-brk
Please sign in to leave a comment.
- you don't need using --inspect-brk in your script: when you choose to debug it, the IDE will pass this option to each child process started with it
- if you like to control the way scripts are started, etc., you can run your script that use node --inspect-brk dist/main.js and attach a debugger to it using Attach to Node.js/Chrome run configuration
- another option is disabling
js.debugger.use.node.optionskey in Registry (Help | Find action, typeRegistry...to locate it), replacing --inspect-brk in your script with$NODE_DEBUG_OPTION(or%NODE_DEBUG_OPTION%if you are on Windows) variable and debug your script by right clicking on the debug script in the NPM tab ( as you did) - the IDE witll replace the environment variable with appropriate Node.js option and attach the debuggerElena Pogorelova -- thanks for the extra info, that is helpful. Using the attach option gets us back to where we started before the change. Would the team consider adding this to the release notes for 2019.3?
>Would the team consider adding this to the release notes for 2019.3?
it's not new in 2019.3... Since 2019.1, WebStorm uses the NODE_OPTIONS environment variable to pass the debug flags. Thanks to this, you no longer need to explicitly pass the –inspect flag to the forked processes.
Disabling
js.debugger.use.node.optionskey turns this feature off so that you have to care yourself about passing appropriate flagsI'm asserting that some default behavior has changed with 2019.3...
When:
I right click on the debug script in the npm tab in WebStorm
And choose debug from the option
Then:
The debugger should attach to the process and breakpoints should be hit.
^-- ...was expecting this to work (as it did in 2019.2) and I was not the only member of the team thrown off by this. I did not see documentation of a behavior change which would require using the attach option you mentioned instead. If it's relevant, I'm on MacOS Catalina.
>I right click on the debug script in the npm tab in WebStorm
And choose debug from the option
Then:
The debugger should attach to the process and breakpoints should be hit.
It works for me in both 2019.2 and 2019.3
Please share a sample app where debugging works for you in 2019.2 and doesn't work in 2019.3
Sure - Here are screenshots from a vanilla nestjs app, slightly modified to reflect the tsc-watch method of starting the app:
In 2019.3 -- the process is hanging waiting for the debugger to attach:
In 2019.2 -- the process attaches and the app is available for debugging as expected:
Note the start:debug script line, and "Debug 'start:debug'" is how I'm starting them in each case . You can see that in the new version the behavior has changed.
Here is the app in github:
https://github.com/mkelandis/birdseye
Thanks, recreated; logged as https://youtrack.jetbrains.com/issue/WEB-42932
Still it's not quite clear for me why you need having --inspect-brk in your script - debugger will work without it