Visual Studio Task Runner Error with ES6
Asked Answered
S

1

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

Surovy answered 9/8, 2017 at 1:49 Comment(6)
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.Vardhamana
@Vardhamana according to this document, ES6 is supported: learn.microsoft.com/en-us/scripting/javascript/…Surovy
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.Licking
@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.Surovy
@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.)Licking
@JonathanLonowski Problem solved below. Visual Studio was targeting an old version of Node to run ES6Surovy
S
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.

Surovy answered 9/8, 2017 at 18:39 Comment(2)
Thank you SOOOOO much for this !Swayder
I wish i could upvote this more than once. Thank you.Eradicate

© 2022 - 2024 — McMap. All rights reserved.