I am trying to use Google Closure Compiler on my new project that I plan to write in ES6. I simply try to follow https://www.npmjs.com/package/google-closure-compiler. After I did npm install google-closure-compiler, I tried either the Grunt or the Gulp approach but neither worked for me. I just had a real simple js hello world type of file to test the workflow.
For Grunt my Gruntfile.js:
module.exports = function(grunt) {
require('google-closure-compiler').grunt(grunt);
grunt.initConfig({
'closure-compiler': {
my_target: {
files: {
'dest/output.min.js': ['src/js/**/*.js']
},
options: {
compilation_level: 'SIMPLE',
language_in: 'ECMASCRIPT6_STRICT',
language_out: 'ECMASCRIPT5_STRICT',
create_source_map: 'dest/output.min.js.map',
output_wrapper: '(function(){\n%output%\n}).call(this)\n//# sourceMappingURL=output.min.js.map'
}
}
}
});
And when I run "grunt" I get:
Warning: Promise is not defined Use --force to continue. Aborted due to warnings.
For Gulp, I also followed the Tutorial, and my gulpfile.js is like this:
var gulp = require('gulp'),
gutil = require('gulp-util');
var Promise = require('es6-promise').Promise;
var closureCompiler = require('google-closure-compiler').gulp();
gulp.task('default', function () {
return gulp.src('./src/js/**/*.js', {base: './'})
.pipe(closureCompiler({
compilation_level: 'SIMPLE',
warning_level: 'VERBOSE',
language_in: 'ECMASCRIPT6_STRICT',
language_out: 'ECMASCRIPT5_STRICT',
output_wrapper: '(function(){\n%output%\n}).call(this)',
js_output_file: 'output.min.js'
})).on('error', gutil.log)
.pipe(gulp.dest('./dist/js'));
});
And when I run gulp intially following the tutorial I ran into the Promise not defined error as well but at least I was able to add that es6-promise line to fix the initial problem but then I still get:
events.js:72
throw er; // Unhandled 'error' event
^
Error: not implemented
at Readable._read (_stream_readable.js:465:22)
at Readable.read (_stream_readable.js:341:10)
at Readable.on (_stream_readable.js:720:14)
at Readable.pipe (_stream_readable.js:575:10)
at Transform.CompilationStream._flush (/<my project directory>/node_modules/google-closure-compiler/lib/gulp/index.js:213:17)
at Transform.<anonymous> (_stream_transform.js:130:12)
at Transform.g (events.js:180:16)
at Transform.emit (events.js:117:20)
at finishMaybe (_stream_writable.js:360:12)
at endWritable (_stream_writable.js:367:3)
Any help on making either Grunt or Gulp work?
Upgrade your NodeJS version. The plugins assume native Promises support. It works as far back as NodeJS 0.12.