简体   繁体   中英

Gulp Unhandled 'error' event

I am getting an "Unhandled 'error' event" while running gulp:

events.js:141
      throw er; // Unhandled 'error' event
      ^

Error: spawn gm ENOENT
    at exports._errnoException (util.js:870:11)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:178:32)
    at onErrorNT (internal/child_process.js:344:16)
    at nextTickCallbackWith2Args (node.js:437:9)
    at process._tickCallback (node.js:351:17)

I've found the error is caused by that function in my gulpfile.js:

var taskResizeSprite2x = function() {
    return gulp.src(config.paths.source.sprite + '/*@2x.png')
        .pipe(changed(config.paths.source.sprite + '/*@2x.png'))
        .pipe(gm(function(gmfile) {
            gmfile.size(function(err, value) {
                if(value && (value.width % 2 !== 0 || value.height % 2 !== 0)) {
                    var src = gmfile.name().source;
                    modules.livereload.notify('Retina images must have even size!<br>' + src);

                    throw Error('Retina images must have even size! ' + src);
                }
            })
            return gmfile.resize('50%', '50%');
        }))
        .pipe(rename(function(filepath) {
            filepath.basename = filepath.basename.replace(/@\dx/, '');
        }))
        .pipe(gulp.dest(config.paths.source.sprite));
};

What I should do and how to debug why it happens?

You'll need a function that logs the actual error.

function handleError(err) {
  console.log(err.toString());
  this.emit('end');
}

Then call it when a gulp function throws an error.

.pipe(something({
  Paths: 'somepath'
}))
.on('error', handleError)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM