Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
131
rated 0 times [  134] [ 3]  / answers: 1 / hits: 52604  / 8 Years ago, fri, october 14, 2016, 12:00:00

How do I debug a gulp task defined in my gulpfile.js with a debugger such as the Google Chrome debugger, stepping through the task's code line by line?


More From » node.js

 Answers
12

With Node.js version 6.3+ you can use the --inspect flag when running your task.



To debug a gulp task named css:




  1. Find out where your gulp executable lives. If gulp is installed locally, this will be at node_modules/.bin/gulp. If gulp is installed globally, run which gulp (Linux/Mac) or where gulp (Windows) in a terminal to find it.


  2. Run one of these commands according to your version of Node.js. If required, replace ./node_modules/.bin/gulp with the path to your gulp installation from step 1.




    • Node.js 6.3+: node --inspect --debug-brk ./node_modules/.bin/gulp css

    • Node.js 7+: node --inspect-brk ./node_modules/.bin/gulp css


  3. Use Chrome to browse to chrome://inspect.




The --debug-brk (Node.js 6.3+) and --inspect-brk (Node.js 7+) flags are used to pause code execution on the first line of code of your task. This gives you a chance to open up the Chrome debugger and set breakpoints before the task finishes.



If you don't want the debugger to pause on first line of code, just use the --inspect flag.



You can also install the Node.js Inspector Manager (NIM) extension for Chrome to help with step 3. This will automatically open up a Chrome tab with the debugger ready to go, as an alternative to manually browsing to a URL.


[#60398] Wednesday, October 12, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ishmaelw

Total Points: 528
Total Questions: 96
Total Answers: 103

Location: Venezuela
Member since Sat, Apr 24, 2021
3 Years ago
;