Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gulp-imagemin error: optipng: cannot execute binary file

Tags:

macos

gulp

I'm running a project with Gulp installed on my machine. When running Gulp Watch, my gulp-imagemin crashes the process if I add a new image to the folder. I have all permissions set correctly (checked multiple times) on that folder, and the image also has the correct permissions.

The process throws the following error:

Error: Command failed: /Users/robbert/Sites/wordpress_cyklo/node_modules/gulp-imagemin/node_modules/imagemin/node_modules/imagemin-optipng/node_modules/optipng-bin/vendor/optipng -strip all -clobber -force -fix -o 2 -out /var/folders/kj/wydtr_t92hqgymv2d2v43pjw0000gr/T/9ab534f4-267f-46cb-b99f-372028e6ed5b /var/folders/kj/wydtr_t92hqgymv2d2v43pjw0000gr/T/eabb0414-f9db-4b6f-8242-4c8d25004e1d /Users/robbert/Sites/wordpress_cyklo/node_modules/gulp-imagemin/node_modules/imagemin/node_modules/imagemin-optipng/node_modules/optipng-bin/vendor/optipng: /Users/robbert/Sites/wordpress_cyklo/node_modules/gulp-imagemin/node_modules/imagemin/node_modules/imagemin-optipng/node_modules/optipng-bin/vendor/optipng: cannot execute binary file

Whenever I run Gulp on the folder, I get the same error, except if I run it through my Vagrant VM. How do I fix this? My VM is a lot slower, so I would really want to be able to run Gulp on my main OS.

Edit: Here's the gulp for images:

// ### Images
// `gulp images` - Run lossless compression on all the images.
gulp.task('images', function() {
  return gulp.src(globs.images)
    .pipe(imagemin({
      progressive: true,
      interlaced: true,
      svgoPlugins: [{removeUnknownsAndDefaults: false}, {cleanupIDs: false}]
    }))
    .pipe(gulp.dest(path.dist + 'images'))
    .pipe(browserSync.stream());
});
like image 774
Rvervuurt Avatar asked Apr 29 '16 07:04

Rvervuurt


1 Answers

gulp-imagemin relies on optipng to optimize PNG images. optipng is a native program written in C, not JavaScript. That means when you npm install gulp-imagemin the appropriate executable of optipng for your system architecture is installed.

If you run npm install gulp-imagemin on one system (e.g. Linux) and then copy the entire project including the node_modules folder to another system (e.g. MacOS X), the optipng executable will still be the one for Linux. MacOS X can't run Linux executables.

The same problem could occur even if you don't explicitly copy the project, but accidentally commit the node_modules folder into your repository.

Your best option is to delete the entire node_modules folder and npm install from scratch:

rm -rf node_modules
npm install
like image 85
Sven Schoenung Avatar answered Oct 17 '22 00:10

Sven Schoenung