So I have spent the past couple days trying to get this to work with no luck. Most of the solutions I have found seem to work "okay" for debugging node applications. But I haven't had much luck debugging grunt stand alone. I would like to be able to set breakpoints in my gruntfile and either step through the code with either the browser or an IDE.
I have tried the following:
- Debugging using intelliJ IDE Using Grunt Console (Process finished with exit code 6)
- Debugging with Nodeeclipse (This sort of works okay but doesn't hit the breakpoints set in eclipse, not very intuitive)
- Debugging using node-inspector (This one also sort of works. I can step through a little ways using F11 and F10 in chrome. But eventually it just crashes. Using F8 to skip to break point never works.)
ERROR MESSAGE USING NODE-INSPECTOR
So currently node-inspector feels like it has gotten me the closest to what I want. To get here I did the following:
From my grunt directory I ran the following commands:
grunt node-inspector
node --debug-brk Gruntfile.js
And then from there I went to localhost:8080/debug?port=5858
to debug my Gruntfile.js. But like I mentioned above, as soon as I hit F8 to skip to breakpoint it crashes with the above error. Has anybody had any success using this method to try to debug a Gruntfile? So far from my search efforts I have not found a very well documented way of doing this. So hopefully this will be useful or beneficial information for future users. Also I am using Windows 7 by the way. Thanks in advance.
UPDATE:
I have tried the following suggested by @dylants with no luck so far.
Found the grunt.cmd file on windows machine located in
C:\Users\khollenbeck\AppData\Roaming\npm
. Opened upgrunt.cmd
file and found the following....This lead me to
C:\Users\khollenbeck\AppData\Roaming\npm\node_modules\grunt-cli\bin
which contained a file calledgrunt
. And from there at the top of the file. I changed this code#!/usr/bin/env node
to#!/usr/bin/env node --debug-brk
After doing this command
node-inspector C:\path\to\gruntfile grunt
I got the following.Node Inspector v0.7.3 Visit http://localhost:8080/debug?port=5858 to start debugging
Next I ran the
grunt
command from grunt dir. (leaving the server running in original command prompt)
From here I expected Gruntfile.js to show up in the source of chrome dev tools. I also expected to be able to set breakpoints from there. This did not happen. Instead it just ran all the way through the Gruntfile without breaking or loading in the browser.
Edit:
Ah, I see what I did wrong. For some reason I did node --debug-brk with out adding the path C:\Users\khollenbeck\AppData\Roaming\npm\node_modules\grunt-cli\bin\grunt. Its working now, thanks so much. I apologize for dragging this on for so long. But hopefully this will be useful for other windows users in the future.
node-inspector
without any parameters. In step 4, instead of running justgrunt
, trynode --debug-brk C:\Users\khollenbeck\AppData\Roaming\npm\node_modules\grunt-cli\bin\grunt
. If grunt started in debug mode you should seedebugger listening on port 5858
for the output of that command. – Mcnultynode --debug-brk ...
command. Simply step through using Chrome, and if you need to re-run, execute the samenode --debug-brk ...
command again. I've updated my answer below to hopefully better explain. – Mcnultynode --debug-brk
with out adding the pathC:\Users\khollenbeck\AppData\Roaming\npm\node_modules\grunt-cli\bin\grunt
. Its working now, thanks so much. I apologize for dragging this on for so long. But hopefully this will be useful for other windows users in the future. – Sagittarius