Samuel Hill
Samuel Hill

Reputation: 186

Gulp fails on uglify() unhandled error event

I'm having trouble with my squish-jquery task. When it runs, it throws this error:

Starting 'squish-jquery'...

events.js:85
      throw er; // Unhandled 'error' event
            ^
Error
    at new JS_Parse_Error (/Users/shill7/Documents/socialprojects/social-ops-dashboard-angular/node_modules/gulp-uglify/node_modules/uglify-js/lib/parse.js:196:18)
    at js_error (/Users/shill7/Documents/socialprojects/social-ops-dashboard-angular/node_modules/gulp-uglify/node_modules/uglify-js/lib/parse.js:204:11)
    at croak (/Users/shill7/Documents/socialprojects/social-ops-dashboard-angular/node_modules/gulp-uglify/node_modules/uglify-js/lib/parse.js:679:41)
    at token_error (/Users/shill7/Documents/socialprojects/social-ops-dashboard-angular/node_modules/gulp-uglify/node_modules/uglify-js/lib/parse.js:683:9)
    at expect_token (/Users/shill7/Documents/socialprojects/social-ops-dashboard-angular/node_modules/gulp-uglify/node_modules/uglify-js/lib/parse.js:696:9)
    at expect (/Users/shill7/Documents/socialprojects/social-ops-dashboard-angular/node_modules/gulp-uglify/node_modules/uglify-js/lib/parse.js:699:36)
    at function_ (/Users/shill7/Documents/socialprojects/social-ops-dashboard-angular/node_modules/gulp-uglify/node_modules/uglify-js/lib/parse.js:959:9)
    at expr_atom (/Users/shill7/Documents/socialprojects/social-ops-dashboard-angular/node_modules/gulp-uglify/node_modules/uglify-js/lib/parse.js:1188:24)
    at maybe_unary (/Users/shill7/Documents/socialprojects/social-ops-dashboard-angular/node_modules/gulp-uglify/node_modules/uglify-js/lib/parse.js:1358:19)
    at expr_ops (/Users/shill7/Documents/socialprojects/social-ops-dashboard-angular/node_modules/gulp-uglify/node_modules/uglify-js/lib/parse.js:1393:24)

I've looked it up, but unfortunately, I can't find anything relevant to my error. Is it a problem with my setup or with Uglify? Here is my gulpfile.js:

    // Load Gulp
var gulp    = require('gulp'),
    gutil   = require('gulp-util');
    plugins = require('gulp-load-plugins')();

var imagemin = require('gulp-imagemin');
var pngquant = require('imagemin-pngquant');
var ignore = require('gulp-ignore');

// Start Watching: Run "gulp"
gulp.task('default', ['watch']);

// Minify jQuery Plugins: Run manually with: "gulp squish-jquery"
gulp.task('squish-jquery', function() {
  return gulp.src(['src/bower_components/**/*.js', '!src/bower_components/**/*.min.js'])
    .pipe(ignore.exclude([ "**/*.map" ]))
    .pipe(plugins.uglify())
    .pipe(plugins.concat('jquery.plugins.min.js'))
    .pipe(gulp.dest('build')).on('error', gutil.log);
});

// Minify Custom JS: Run manually with: "gulp build-js"
gulp.task('build-js', function() {
  return gulp.src(['src/js/**/*.js', 'src/js/components-controllers/*.js'])
    .pipe(plugins.jshint())
    .pipe(plugins.jshint.reporter('jshint-stylish'))
    .pipe(plugins.uglify())
    .pipe(plugins.concat('scripts.min.js'))
    .pipe(gulp.dest('build'));
});

// Less to CSS: Run manually with: "gulp build-css"
gulp.task('build-css', function() {
    return gulp.src('src/less/all.less')
        .pipe(plugins.plumber())
        .pipe(plugins.less())
        .on('error', function (err) {
            gutil.log(err);
            this.emit('end');
        })
        .pipe(plugins.autoprefixer(
            {
                browsers: [
                    '> 1%',
                    'last 2 versions',
                    'firefox >= 4',
                    'safari 7',
                    'safari 8',
                    'IE 8',
                    'IE 9',
                    'IE 10',
                    'IE 11'
                ],
                cascade: false
            }
        ))
        .pipe(plugins.cssmin())
        .pipe(gulp.dest('build')).on('error', gutil.log);
});

//Image minification
gulp.task('imagemin', function() {
    return gulp.src('src/images/*')
        .pipe(imagemin({
            progressive: true,
            svgoPlugins: [{removeViewBox: false}],
            use: [pngquant()]
        }))
        .pipe(gulp.dest('build/images'));
});

// Default task
gulp.task('watch', function() {
    gulp.watch('src/bower_components/**/*.js', ['squish-jquery']);
    gulp.watch('src/js/**.js', ['build-js']);
    gulp.watch('src/images/*', ['imagemin']);
    gulp.watch('src/less/**/*.less', ['build-css']);
});

Upvotes: 6

Views: 5454

Answers (1)

Gary Storey
Gary Storey

Reputation: 1814

Per my comment above, you should turn on error logging for the uglify plugin to determine where the error is acrually occurring:

//....
.pipe(uglify())
.on('error', function(){
  //do whatever here
})
//....

Upvotes: 5

Related Questions