terinjokes/gulp-uglify

Minification failing with Node v10

unigazer opened this issue · 8 comments

While the Node version was <= 9 the plugin worked without any problems. Since Node v10 came out, problems started to occur.

events.js:167
      throw er; // Unhandled 'error' event
      ^
GulpUglifyError: unable to minify JavaScript
    at createError (/home/wiseman/Desktop/Website-Template/node_modules/gulp-uglify/lib/create-error.js:6:14)
    at apply (/home/wiseman/Desktop/Website-Template/node_modules/lodash/_apply.js:16:25)
    at wrapper (/home/wiseman/Desktop/Website-Template/node_modules/lodash/_createCurry.js:41:12)
    at /home/wiseman/Desktop/Website-Template/node_modules/gulp-uglify/lib/minify.js:54:15
    at DestroyableTransform._transform (/home/wiseman/Desktop/Website-Template/node_modules/gulp-uglify/composer.js:10:23)
    at DestroyableTransform.Transform._read (/home/wiseman/Desktop/Website-Template/node_modules/readable-stream/lib/_stream_transform.js:184:10)
    at DestroyableTransform.Transform._write (/home/wiseman/Desktop/Website-Template/node_modules/readable-stream/lib/_stream_transform.js:172:83)
    at doWrite (/home/wiseman/Desktop/Website-Template/node_modules/readable-stream/lib/_stream_writable.js:428:64)
    at writeOrBuffer (/home/wiseman/Desktop/Website-Template/node_modules/readable-stream/lib/_stream_writable.js:417:5)
    at DestroyableTransform.Writable.write (/home/wiseman/Desktop/Website-Template/node_modules/readable-stream/lib/_stream_writable.js:334:11)
Emitted 'error' event at:
    at DestroyableTransform.onerror (/home/wiseman/Desktop/Website-Template/node_modules/readable-stream/lib/_stream_readable.js:640:52)
    at DestroyableTransform.emit (events.js:182:13)
    at onwriteError (/home/wiseman/Desktop/Website-Template/node_modules/readable-stream/lib/_stream_writable.js:443:12)
    at onwrite (/home/wiseman/Desktop/Website-Template/node_modules/readable-stream/lib/_stream_writable.js:470:11)
    at WritableState.onwrite (/home/wiseman/Desktop/Website-Template/node_modules/readable-stream/lib/_stream_writable.js:180:5)
    at DestroyableTransform.afterTransform (/home/wiseman/Desktop/Website-Template/node_modules/readable-stream/lib/_stream_transform.js:93:3)
    at DestroyableTransform._transform (/home/wiseman/Desktop/Website-Template/node_modules/gulp-uglify/composer.js:13:9)
    at DestroyableTransform.Transform._read (/home/wiseman/Desktop/Website-Template/node_modules/readable-stream/lib/_stream_transform.js:184:10)
    at DestroyableTransform.Transform._write (/home/wiseman/Desktop/Website-Template/node_modules/readable-stream/lib/_stream_transform.js:172:83)
    at doWrite (/home/wiseman/Desktop/Website-Template/node_modules/readable-stream/lib/_stream_writable.js:428:64)
npm ERR! code ELIFECYCLE

Have you use pump has shown in the README to print the formatted error message?

@terinjokes
No. I will try that and update this issue.
Thanks for the tip.

Node: 10.1
npm: 6.0.1
OS: Linux Mint 18.3 64-bit

After trying the code from README

gulp.task('scripts', cb => {
    pump([
            gulp.src('src/js/*.js'),
            concat('main.min.js'),
            uglify(),
            gulp.dest('./public/dist/js')
        ],
        cb
    );
});

Still doesn't work, however, it prints a different error now (same error prints without pump after upgrading from node v8 to v10.1)

GulpUglifyError: unable to minify JavaScript
Caused by: SyntaxError: Unexpected token: punc ())
File: /home/wiseman/Desktop/Website-Template/src/js/main.min.js
Line: 7

I have an ES6 code in that file (main.min.js) so maybe that's causing the problem.
Line: 7

var myFunction = () => alert(msg);

I remember switching from const to var and that line passed without any errors.

The rest of the gulp tasks execute successfully.

For example:

gulp.task('stylesheet', () => {
    return gulp.src('src/css/*.css')
        .pipe(concat('style.min.css'))
        .pipe(minifyCSS())
        .pipe(gulp.dest('./public/dist/css'));
});

which uses gulp-csso

The default version of UglifyJS used doesn't support ES6. You can follow steps in the README as an alternative.

Ok

After following the instructions from here https://github.com/terinjokes/gulp-uglify#using-a-different-uglifyjs
the task executes successfully. Thank you.

Will your module support ES6+ in the future?

I'm keeping an eye on forks of UglifyJS, but for now this module will get ES6+ support when it's added to UglifyJS.