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

后端 未结 1 616
萌比男神i
萌比男神i 2021-02-13 22:06

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.

I

1条回答
  •  轮回少年
    2021-02-13 22:47

    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).

    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. 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 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.

    0 讨论(0)
提交回复
热议问题