简体   繁体   中英

How can I debug Gulp tasks using Node Tools for Visual Studio?

I recently installed NodeJS Tools for Visual Studio which touts support for Node environments in VS. Notably, it has the ability to set debug breakpoints from the IDE.

It's unclear to me if it is possible to set breakpoints when debugging Gulp tasks. The Task Runner has the ability to detect the Gulp task and output console.log statements to a window, but I haven't found a better means of debugging.

I found this post from a while back: How can I debug gulpfile.js when running it with Visual Studio Task Runner Explorer? However, this post doesn't involve NodeJS Tools for VS. So, I'm re-asking the question to take that plugin into consideration.

在此输入图像描述

You can. Right-click the Node project, select Properties , and configure your app as follows (in the image, default is the Gulp task that you want to run).

使用VS进行调试

Alternative method:

  1. In a terminal, and in the directory where the gulpfile is, run node --debug=44331 --debug-brk ../node_modules/gulp/bin/gulp.js default . In my case, default is the task name I want to run/debug.
  2. In Visual Studio, go to Debug | Attach to Process Debug | Attach to Process . Select Node.js Remote debugging as Transport, and in the qualifier select localhost:44331 . Press enter and you should see the Node process appear in the list. Click Attach .

附加到流程

Voila, the breakpoints are hit.

断点被击中

A couple of things to notice:

  • If you get something like Unable to attach to process. Error 0x80004005 Unable to attach to process. Error 0x80004005 use a different port. I couldn't get it to work with port 5858.
  • It may not work the first time you attach to the process (see my previous screenshot how I got ECANCELED ?). Try again.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM