最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Gulp fails on uglify() unhandled error event - Stack Overflow

programmeradmin2浏览0评论

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_ponents/**/*.js', '!src/bower_ponents/**/*.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/ponents-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_ponents/**/*.js', ['squish-jquery']);
    gulp.watch('src/js/**.js', ['build-js']);
    gulp.watch('src/images/*', ['imagemin']);
    gulp.watch('src/less/**/*.less', ['build-css']);
});

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_ponents/**/*.js', '!src/bower_ponents/**/*.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/ponents-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_ponents/**/*.js', ['squish-jquery']);
    gulp.watch('src/js/**.js', ['build-js']);
    gulp.watch('src/images/*', ['imagemin']);
    gulp.watch('src/less/**/*.less', ['build-css']);
});
Share Improve this question edited Apr 30, 2015 at 20:23 Samuel Hill asked Apr 30, 2015 at 20:04 Samuel HillSamuel Hill 1861 silver badge14 bronze badges 7
  • Which line is on line 85? – Gary Storey Commented Apr 30, 2015 at 20:09
  • gulp.watch('src/js/ponents-controllers/*.js', ['build-ponents']); – Samuel Hill Commented Apr 30, 2015 at 20:12
  • Sorry in events.js line 85. Looks like it's working but failing validation. – Gary Storey Commented Apr 30, 2015 at 20:14
  • Events.js isn't something I set up. It looks like it's a file in node_modules/karma/lib/. Line 85 is blank. – Samuel Hill Commented Apr 30, 2015 at 20:17
  • what happens if you turn off mangling of the variables? .pipe(plugins.uglify( { mangle : false )) or do an on('error') after the uglify call? – Gary Storey Commented Apr 30, 2015 at 20:25
 |  Show 2 more ments

1 Answer 1

Reset to default 5

Per my ment 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
})
//....
发布评论

评论列表(0)

  1. 暂无评论