23

I am running Visual Studio 2017 and use the Task Runner to run tasks in my gulpfile. I recently updated a gulp task to ES6 and now am getting this error:

Failed to run "C:\Users\nz9rcn\Code\WebUI\Gulpfile.js"... cmd.exe /c gulp --tasks-simple C:\Users\nz9rcn\Code\WebUI\gulp-tasks\lesslint.js:5 let fail = false; ^^^ SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode at exports.runInThisContext (vm.js:53:16) at Module._compile (module.js:373:25) at Object.Module._extensions..js (module.js:404:10) at Module.load (module.js:343:32) at Function.Module._load (module.js:300:12) at Module.require (module.js:353:17) at require (internal/module.js:12:17) at task (C:\Users\nz9rcn\Code\WebUI\gulpfile.js:24:25) at Object.<anonymous> (C:\Users\nz9rcn\Code\WebUI\gulpfile.js:37:23) at Module._compile (module.js:397:26)

Can't find a place to adjust the settings causing this error (strict mode). Please help. Thanks

Ben Rondeau
  • 2,983
  • 1
  • 15
  • 21
  • Are you sure Visual Studio supports ES6 out of the box? By the error it looks like it doesn't recognize ES6 syntax - maybe you need a tool like Babel to transpire first? Not sure how that would be accomplished with this task runner though. – ryandrewjohnson Aug 09 '17 at 01:59
  • @ryandrewjohnson according to this document, ES6 is supported: https://learn.microsoft.com/en-us/scripting/javascript/javascript-in-vs-2017 – Ben Rondeau Aug 09 '17 at 02:53
  • [Strict mode](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode) is a language feature that's enabled within code. Include `"use strict";` either as the 1st line of the file or 1st line of the function's body that's using `let`. – Jonathan Lonowski Aug 09 '17 at 03:05
  • @JonathanLonowski I believe the issue is that Visual Studio is choosing to run code in 'use strict' mode, as I do not have the statement in my code, and therefore needs to be turned off in VS. I can't remove it from my code because it is not there. – Ben Rondeau Aug 09 '17 at 16:33
  • @BenRondeau It should be the other way. To use `let`, you'll have to use strict mode. Since you haven't opted into the mode, the declaration isn't permitted. (Though, that was a temporary restriction in Google's V8. The version in Node 8 should allow `let` both with and without strict mode.) – Jonathan Lonowski Aug 09 '17 at 17:40
  • @JonathanLonowski Problem solved below. Visual Studio was targeting an old version of Node to run ES6 – Ben Rondeau Aug 09 '17 at 18:39

1 Answers1

40

Issue solved by un-checking the box for the Node.js binary used by Task Runner:

enter image description here

In the menu, go to Tools > Options > Projects and Solutions > Web Package Management > External Web Tools and DESELECT the option for $(VSINSTALLDIR)\Web\External

The version installed in that directory doesn't support ES6 apparently.

References for solution here and here.

Ben Rondeau
  • 2,983
  • 1
  • 15
  • 21