yeoman / generator-webapp

A gulp.js generator for modern webapps
3.77k stars 708 forks source link

SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode #684

Closed MySecret closed 7 years ago

MySecret commented 7 years ago

when I input command 'gulp serve',it throw an error "SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode"

sindresorhus commented 7 years ago

Upgrade Node.js

branb commented 6 years ago

I'm not sure which version of Node.js is required to not have this bug appear, but for my version:

node --version
v4.4.3

this bug occurs as well.

Instead of upgrading Node.js, I just forced strict mode in gulpfile.js by adding this on top:

'use strict';

See: https://github.com/gulpjs/gulp/issues/1325

Initially, I got the information of why the error shows up in the first place here: https://www.npmjs.com/package/strict-mode#use-case

At the time of this writing Node v4 stable version was released few days ago. Finally we can use class, let, const (among other new exciting features) but you will notice that if you do not turn on strict mode an exception will raise. For instance, a file Point2d.js with content

Not sure if versions >4.4.3 of Node.js solve this problem, but from what I understand, you can't use let without specifying 'use strict';