Gulp -imagemin error: optipng: unable to execute binary

I am running a project with Gulp installed on my machine. When Gulp Watch starts, my gulp -imagemin crashes if I add a new image to the folder. I have all the permissions set correctly (checked several times) in this 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 / seller / OptiPNG -strip all -clobber -force -fix -o 2 -out / var / folders / kj / wydtr_t92hqgymv2d2v43pjw0000gr / T / 9ab534f4-267f-46cb-b99f-372028e6ed5b / Var / folders / KJ / wydtr_t92hqgybvdbdbdbbdbdbbbdbdbbd4 wordpress_cyklo / node_modules / gulp -imagemin / node_modules / imagemin / node_modules / imagemin-OptiPNG / node_modules / OptiPNG-bin / seller / OptiPNG: / Users / Robbert / Sites / wordpress_cyklo / node_modules / gulp-imageagemin / node_modules / image_modules -OptiPNG / node_modules / OptiPNG-bin / seller / OptiPNG: cannot execute binary

Whenever I run Gulp in a folder, I get the same error, except when I run it through my Vagrant VM. How to fix it? My virtual machine is much slower, so I really want to be able to run Gulp on my main OS.

Edit: Here's the gulp for the 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()); }); 
+7
gulp macos
source share
1 answer

gulp-imagemin relies on optipng to optimize PNG images. optipng is a native program written in C, not JavaScript. This means that with npm install gulp-imagemin , the corresponding optipng executable is optipng for your system architecture.

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 for Linux. MacOS X cannot run Linux executables.

The same problem can occur even if you do not explicitly copy the project, but accidentally copy the node_modules folder to your repository.

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

 rm -rf node_modules npm install 
+7
source share

All Articles