-->

Gulp task failing when run from VS 2015 Task Runne

2019-01-11 14:41发布

问题:

I have some Gulp tasks to do the typical clean, build, release actions for a website. Nothing particularly unusual in my mind. (In fact it's very similar to Aurelia TypeScript skeleton.)

Most of the team does front-end development using Gulp from a PowerShell / Command prompt and editing with VS Code / Sublime. Some of the team does the same using Visual Studio 2015.

Running the build task from the command prompt works just fine, but if we run it from Visual Studio's Task Runner Explorer, it gives us an error.

However, running the other tasks (e.g. clean) works just fine from both the command prompt and the VS Task Runner Explorer.

Interestingly, the Task Runner explorer even outputs a copy of the process it invokes to run the task. If I copy that exact command (see below) and run that in a command prompt, it does not give the error. It only happens when run from Task Runner Explorer, and only that one task.

Here's the task command line and related error output from the Task Runner Explorer:

cmd.exe /c gulp -b "D:\Development\xxxx\WebSite" --color --gulpfile "D:\Development\xxxx\WebSite\Gulpfile.js" build
[20:40:42] Using gulpfile D:\Development\xxxx\WebSite\Gulpfile.js
[20:40:42] Starting 'build'...
[20:40:42] Starting 'clean'...
[20:40:42] Finished 'clean' after 5.74 ms
[20:40:42] Starting 'build-system'...
[20:40:42] Starting 'build-html'...
[20:40:42] Starting 'build-css'...
[20:40:42] Finished 'build-css' after 31 ms
[20:40:43] Finished 'build-html' after 162 ms
D:\Development\xxxx\WebSite\node_modules\gulp-tsb\lib\builder.js:153
        var newLastBuildVersion = new Map();
                                      ^
ReferenceError: Map is not defined
    at Object.build (D:\Development\xxxx\WebSite\node_modules\gulp-tsb\lib\builder.js:153:39)
    at Stream.<anonymous> (D:\Development\xxxx\WebSite\node_modules\gulp-tsb\lib\index.js:40:22)
    at _end (D:\Development\xxxx\WebSite\node_modules\through\index.js:65:9)
    at Stream.stream.end (D:\Development\xxxx\WebSite\node_modules\through\index.js:74:5)
    at DestroyableTransform.onend (D:\Development\xxxx\WebSite\node_modules\readable-stream\lib\_stream_readable.js:545:10)
    at DestroyableTransform.g (events.js:180:16)
    at DestroyableTransform.emit (events.js:117:20)
    at endReadableNT (D:\Development\xxxx\WebSite\node_modules\readable-stream\lib\_stream_readable.js:960:12)
Process terminated with code 8.
    at afterTick (D:\Development\xxxx\WebSite\node_modules\process-nextick-args\index.js:18:8)
    at process._tickCallback (node.js:419:13)

My Google-Fu has come up empty on the error message / stack trace or related searches.

What gives?

UPDATE: As per @josh-graham, the version of Node being invoked by VS is listed below.

[10:12:48] Starting 'clean'...
Version: v0.10.31
[10:12:48] Finished 'clean' after 42 ms

回答1:

VS ships with an old version of Node.js and does not indicate whether an update will be coming any time soon, even with Update 2 coming out. Your system likely has a newer version. To fix this in Visual Studio, you need to prioritize your PATH (assuming you have node on your PATH). Simply find the "External Web Tools" option, and move $(PATH) to the top of the following...

See this for more detail - Customize external web tools in Visual Studio 2015. Also, sorry for the picture, but it seems to be the most straightforward way to explain the issue.


After seeing this answer grow in popularity to help others, I continued to dig into why this is still somehow an issue. I looked into the current Node.js Tools remarks for update 3 and still do not see any information regarding a version in their summary of updates as follows...

  • Faster, better ES6 IntelliSense
  • More reliable debugging
  • Improved Unit Testing experiences (including Tape support)
  • .npm command in more project types

To go down the rabbit hole a little bit to see if their exact version choice is glaringly obvious (which it is not) I did find the following on their github repository...

this.versions = {node: '0.10.0', v8: '3.14.5.8'};

Could this be it? Unsure, but I'm thinking they're still not on board with shipping VS with newer versions of Node.js.



回答2:

See if you can print out the node version that Visual Studio is shelling out to. It is likely that the version of Node that Visual Studio is using is different than the one you are using at the console. The Map collection looks like it was introduced in Node v4.0.0 https://nodejs.org/en/blog/release/v4.0.0/

You should be able to log the Node version using

console.log('Version: ' + process.version);