How can I debug gulpfile.js when running it with Visual Studio Task Runner Explorer?
Asked Answered
D

2

24

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.

Daw answered 8/2, 2015 at 0:10 Comment(3)
Does this answer help? https://mcmap.net/q/583848/-how-can-i-debug-gulp-tasks-using-node-tools-for-visual-studioNadiya
Possible duplicate of How can I debug Gulp tasks using Node Tools for Visual Studio?Daw
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.Daw
H
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.

Hoof answered 4/6, 2015 at 15:1 Comment(9)
I wás hoping for something better, but thanks for the answer :).Rickety
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.Perron
Is this answer still current? VS NodeJS Tools has been released?Curr
VS Code can be used to debug it. hansrwindhoff.wordpress.com/2015/05/05/…Buoyage
@sotn That article is about VS Code, not the regular VS.Stun
@Stun that's why I put it into comments section but not as an answer :)Buoyage
I have not tried this but it seems promising so have a look as this as well https://mcmap.net/q/583849/-how-to-debug-gulpfile-js if you have the time or inclination :)Hoof
I tried to use console.log() but I don't see where are results. They are not in "Output" window, so where are they?Nicolle
have you switched to the appropriate "Show Output From" in the Output window?Hoof
H
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.

Helmut answered 4/5, 2017 at 14:14 Comment(2)
The op asked for VS not Code.Diecious
So, 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?Nicolle

© 2022 - 2024 — McMap. All rights reserved.