How can I debug gulpfile.js when running it with Visual Studio Task Runner Explorer? Or is there another way gulp may be launched with visual studio such that gulpfile.js may be debugged? I am aware of node-inspector but want to see if there is something native to Visual Studio.
Asked
Active
Viewed 8,130 times
24
-
1Does this answer help? http://stackoverflow.com/a/43576225/1623249 – Maria Ines Parnisari Apr 23 '17 at 20:39
-
1Possible duplicate of [How can I debug Gulp tasks using Node Tools for Visual Studio?](http://stackoverflow.com/questions/34211004/how-can-i-debug-gulp-tasks-using-node-tools-for-visual-studio) – Richard Collette Apr 25 '17 at 13:57
-
Yes that helps. Although this is not explicitly a duplicate question, I would say the question is now out of date and the answer posted above is more pertinent. Because of that I've voted to close my own question as a duplicate. – Richard Collette Apr 25 '17 at 13:58
2 Answers
8
I know that you may expect a better way of doing this but he way I currently do it is by using plain
console.log() statements inside the gulpfile.js
That way I can inspect the variables and try and spot any logic errors.

joshcomley
- 28,099
- 24
- 107
- 147

Byron
- 691
- 9
- 9
-
4
-
Me too, in WebStorm I can right-click on a task and select run or debug. If i select debug it hits my breakpoints in the gulpfile. – Serge van den Oever Nov 20 '15 at 22:42
-
6Is this answer still current? VS NodeJS Tools has been released? – Sean Anderson Dec 10 '15 at 20:12
-
VS Code can be used to debug it. https://hansrwindhoff.wordpress.com/2015/05/05/debugging-task-runner-tasks-like-gulp-with-visual-studio-code-editordebugger/ – yakya Feb 18 '17 at 17:25
-
-
-
I have not tried this but it seems promising so have a look as this as well http://stackoverflow.com/questions/29201843/how-to-debug-gulpfile-js if you have the time or inclination :) – Byron Apr 21 '17 at 13:51
-
I tried to use console.log() but I don't see where are results. They are not in "Output" window, so where are they? – vkelman Nov 29 '17 at 20:36
-
1have you switched to the appropriate "Show Output From" in the Output window? – Byron Dec 06 '17 at 09:13
2
Define a .vscode\launch.json
file in the folder you "Open Folder" to in VS Code with this content:
{
// Use IntelliSense to learn about possible Node.js debug attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"cwd": "${workspaceRoot}/src/node",
"name": "Gulp package node",
"program": "${workspaceRoot}/src/node/node_modules/gulp/bin/gulp.js",
"args": [
"package" // replace this with your gulp task name
]
}
]
}
You'll obviously want to replace the task name and the path to your code in the above.
Then you can just hit "Go" in VS Code and it will launch gulp with the debugger attached.

Andrew Arnott
- 80,040
- 26
- 132
- 171
-
6
-
1So, is there a way to debug gulpfile.js in Visual Studio 2017? Is there a way to stop on breakpoints? If not, is there a way to see console.log output? – vkelman Nov 30 '17 at 19:56