gulp-uglify events.js未处理'错误'事件

时间:2015-06-23 12:57:38

标签: gulp gulp-uglify

我收到此错误。昨天运行gulp工作得非常好,但是今天早上(更改了NO代码)并且我收到了这个错误。

$ gulp
[08:54:10] Using gulpfile C:\Source\Source2\bunny-meadows\gulpfile.js
[08:54:10] Starting 'scripts'...
[08:54:10] 'scripts' errored after 11 ms
[08:54:10] TypeError: listener must be a function
    at TypeError (<anonymous>)
    at DestroyableTransform.addListener (events.js:130:11)
    at DestroyableTransform.Readable.on (C:\Source\Source2\bunny-meadows\node_mo
dules\gulp-uglify\node_modules\through2\node_modules\readable-stream\lib\_stream
_readable.js:729:33)
    at Gulp.<anonymous> (C:\Source\Source2\bunny-meadows\gulpfile.js:37:10)
    at module.exports (C:\Source\Source2\bunny-meadows\node_modules\gulp\node_mo
dules\orchestrator\lib\runTask.js:34:7)
    at Gulp.Orchestrator._runTask (C:\Source\Source2\bunny-meadows\node_modules\
gulp\node_modules\orchestrator\index.js:273:3)
    at Gulp.Orchestrator._runStep (C:\Source\Source2\bunny-meadows\node_modules\
gulp\node_modules\orchestrator\index.js:214:10)
    at Gulp.Orchestrator.start (C:\Source\Source2\bunny-meadows\node_modules\gul
p\node_modules\orchestrator\index.js:134:8)
    at c:\Users\hschillig.SCDL\AppData\Roaming\npm\node_modules\gulp\bin\gulp.js
:129:20
    at process._tickCallback (node.js:419:13)

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error
    at new JS_Parse_Error (C:\Source\Source2\bunny-meadows\node_modules\gulp-ugl
ify\node_modules\uglify-js\lib\parse.js:196:18)
    at js_error (C:\Source\Source2\bunny-meadows\node_modules\gulp-uglify\node_m
odules\uglify-js\lib\parse.js:204:11)
    at croak (C:\Source\Source2\bunny-meadows\node_modules\gulp-uglify\node_modu
les\uglify-js\lib\parse.js:675:9)
    at token_error (C:\Source\Source2\bunny-meadows\node_modules\gulp-uglify\nod
e_modules\uglify-js\lib\parse.js:683:9)
    at expect_token (C:\Source\Source2\bunny-meadows\node_modules\gulp-uglify\no
de_modules\uglify-js\lib\parse.js:696:9)
    at expect (C:\Source\Source2\bunny-meadows\node_modules\gulp-uglify\node_mod
ules\uglify-js\lib\parse.js:699:36)
    at function_ (C:\Source\Source2\bunny-meadows\node_modules\gulp-uglify\node_
modules\uglify-js\lib\parse.js:959:9)
    at expr_atom (C:\Source\Source2\bunny-meadows\node_modules\gulp-uglify\node_
modules\uglify-js\lib\parse.js:1188:24)
    at maybe_unary (C:\Source\Source2\bunny-meadows\node_modules\gulp-uglify\nod
e_modules\uglify-js\lib\parse.js:1358:19)
    at expr_ops (C:\Source\Source2\bunny-meadows\node_modules\gulp-uglify\node_m
odules\uglify-js\lib\parse.js:1393:24)
    at maybe_conditional (C:\Source\Source2\bunny-meadows\node_modules\gulp-ugli
fy\node_modules\uglify-js\lib\parse.js:1398:20)
    at maybe_assign (C:\Source\Source2\bunny-meadows\node_modules\gulp-uglify\no
de_modules\uglify-js\lib\parse.js:1422:20)

我的gulpfile.js看起来像这样:

var gulp = require('gulp');

// Include Our Plugins
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
var livereload = require('gulp-livereload');

var paths = {
    // using framework version of jquery
    scripts: [
        'public/assets/js/jquery.min.js',
        'public/assets/plugins/mustachejs/mustache.js',
        'public/assets/js/modernizr.js',
        'public/assets/js/bootstrap.min.js',
        'public/assets/js/placeholders.min.js',
        'public/assets/plugins/bootstrap-wysiwyg/bootstrap3-wysihtml5.all.min.js',
        'public/assets/plugins/bootstrap-wysiwyg/bootstrap3-wysihtml5.min.js',
        'public/assets/plugins/responsiveslides/responsiveslides.min.js',
        'public/assets/plugins/bxslider/jquery.bxslider.min.js',
        'public/assets/plugins/magnific-popup/magnific-popup.js',
        'public/assets/js/jquery.autocomplete.min.js',
        'public/assets/js/plugins/additems.js',
        'public/assets/js/plugins/farm/farm.js',
        'public/assets/js/plugins/plusminus.js',
        'public/assets/js/core.js'
    ]
};

// Concatenate & Minify JS
gulp.task('scripts', function() {
    return gulp.src(paths.scripts)
        .pipe(concat('all.js'))
        .pipe(gulp.dest('public/assets/js'))
        .pipe(rename('all.min.js'))
        .pipe(uglify())
        .on('error')
        .pipe(gulp.dest('public/assets/js'))
        .pipe(livereload());
});

// Watch Files For Changes
gulp.task('watch', function() {
    livereload.listen();
    gulp.watch(paths.scripts, ['scripts']);
});

// Default Task
gulp.task('default', ['scripts', 'watch']);

我再一次没有做任何改变,所以我不知道为什么今天早上它突然想要工作。

2 个答案:

答案 0 :(得分:27)

这有助于:

  1. 安装Gulp-util
  2. 使用以下语句导入Gulp-util:var gutil = require('gulp-util');
  3. 最后,在您放弃代码时,请附上错误处理程序,如下所示:.pipe(uglify().on('error', gutil.log))
  4. 我能够调试它。这是我所包含的一个缩小文件中的语法错误。

答案 1 :(得分:0)

理解Gulp管道中的错误的最佳方法是使用辅助模块,例如$scope.All = function(){ $http.get('/App/getAll.php') .then(function(data){ $scope.clients = data.data; }); } 。正如Gulp文档 Why Use Pump? 中所述,您可以通过包装管道来获得正确的错误。

pump

将错误处理程序附加到管道的UglifyJS部分不会告诉您其他部分中的错误,并且它不会正确地向Gulp的任务运行系统发出错误信号。