Gulp task failing when run from VS 2015 Task Runner explorer, but not from command prompt
Asked Answered
R

2

13

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
Remit answered 9/3, 2016 at 11:13 Comment(0)
A
44

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

enter image description here

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.

Alic answered 10/3, 2016 at 0:26 Comment(5)
Ha-ha... will this happened concurrently! Thanks for the clear answer. I'll revise the correct answer. Also, the picture is even easier to follow than Mads' post.Remit
For google, I was getting this error: Node Sass could not find a binding for your current environment: Windows 32-bit with Node.js 5.xGraner
This applies also to the newly-released Visual Studio 2017.Aerobatics
@AlenSiljak Wow, we're at the point where staple node modules only support 4.x and onward. I honestly don't understand this from MicrosoftAlic
I have checked it on vs15 and it works like charm! but be sure to restart the vs again after reorderingTilton
M
1

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

Mcclelland answered 9/3, 2016 at 16:44 Comment(1)
I think you might be onto something here. The version being output is v0.10.31 !? This is despite having node v4.2.6 installed. Now for VS to get with the program...Remit

© 2022 - 2024 — McMap. All rights reserved.