2020-12-01 16:53

Skipping files which give "Premature end of JPEG file"

When using gulp-imagemin to minimize thousands of files (16,000).

In this directory there are about a 1000 damaged files that give "Premature end of JPEG file" error.

Is there a way to skip optimization for these files without crashing the task?

Does anyone have a solution ?


      throw er; // Unhandled 'error' event
Error: Premature end of JPEG file

    at Promise.all.then.arr (D:\php_workspace\photo_shrink\2f076e49f92998893f1b4004ebf9de6e\node_modules\execa\index.js:202:11)

CODE: gulp.task('default', function(){ return gulp.src([from + '//*.png',from + '//.jpg',from + '//.jpeg',from + '/*/.gif']) .pipe(filelog()) .pipe(imagemin()) .pipe(gulp.dest(to)); });



  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答


  • weixin_39775910 weixin_39775910 4月前

    Did you figure this out? I'm having the same issue.

    点赞 评论 复制链接分享
  • weixin_39739404 weixin_39739404 4月前

    I looked in the code 'events.js' where it gives the error and I just commented it out. That way it doesn't break the process when it fails in the conversion. (the problem is due to a corrupt JPEG file). just comment out the 'throw er' line.

    点赞 评论 复制链接分享
  • weixin_39775910 weixin_39775910 4月前

    Thanks ☺️ I ended up installing gulp-debug and tracking down which photos it was breaking on and manually removing them.

    点赞 评论 复制链接分享
  • weixin_39760967 weixin_39760967 4月前
    .pipe(imagemin().on('error', function(e){}))

    Hope it helps.

    点赞 评论 复制链接分享