Imagemin issue

I’ve encountered the following error - below. I have tried reinstalling node (clearing cache after uninstall), a fresh install of Sage 8.2.1, and a few other suggestions I had found. I’m running Node V 0.12.3, Bower V 1.4.1, Gulp V 3.8.11, PHP 5.5.2.

This error is thrown after executing “gulp” command when attempting to optimize images (Starting ‘images’). If no images to optimize in assets/images, no error. Everything worked brilliantly at first, then this just started happening; nothing changed on my end that I’m aware of.

Any suggestions greatly appreciated!

throw er; // Unhandled ‘error’ event
Error: spawn /Users/inHouse/Documents/www/vagrant/www/devtheme/htdocs/wp-content/themes/devtheme/node_modules/gulp-imagemin/node_modules/imagemin/node_modules/imagemin-optipng/node_modules/optipng-bin/vendor/optipng ENOENT
at exports._errnoException (util.js:746:11)
at Process.ChildProcess._handle.onexit (child_process.js:1053:32)
at child_process.js:1144:20
at process._tickCallback (node.js:355:11)

Same problem:

throw er; // Unhandled ‘error’ event
Error: spawn /Applications/MAMP/htdocs/casualhoteles/wp-content/themes/casualhoteles/node_modules/gulp-imagemin/node_modules/imagemin/node_modules/imagemin-optipng/node_modules/optipng-bin/vendor/optipng ENOENT
at exports._errnoException (util.js:746:11)
at Process.ChildProcess._handle.onexit (child_process.js:1053:32)
at child_process.js:1144:20
at process._tickCallback (node.js:355:11)

Thanks in advance for any ideas.
My case:
Fresh install actual Sage version
Node V 0.12.4
npm V 2.11.1
Bower V 1.4.1
Gulp V 3.9.0
PHP V 5.6.7

It seems the problem only appears when there´s a .png image in assets folder.

I’ve found this Gulp Error: spawn EACCES resulting from images added to asset folder where it gets solved.


I swear I had tried this already, but I just tried again and it did the trick:

delete /node_modules and run npm install. I hope this works for you as well.

Yep, deleting node_modules and running npm install again worked for me too.

Thanks Greg_Hollowell

In my case, I had to run:

rm -rf node-modules/

npm rebuild

since I think the optipng binaries failed to build during the initial npm install process and something wasn’t clearing right in the system. npm rebuild was the thing that did the trick.

1 Like

Ran into this issue on a build of Sage from July 2015. Jpegtran wasn’t minimizing images in the theme’s assets directly. Here’s what I did to resolve it without reinstalling the entire node_modules direcotry.

  1. I removed all of the images from assets
  2. ran gulp to confirm that was causing the error
  3. uninstalled gulp-imagemin
  4. checked the package.json to verify the modules version
  5. installed the build specific version of gulp-imagemin
  6. ran gulp and confirmed it worked
  7. added a test image back to the assets directory
  8. ran gulp and confirmed it worked

$ npm uninstall gulp-imagemin
$ npm install gulp-imagemin@2.3.0
$ gulp

Thanks for posting this. Just curious why you wouldn’t want to reinstall the node_modules directory. I know it can take a few minutes to run npm install, but the method you describe seems a lot more manual time consuming

Overall, this process took me about one minute to complete. I just wrote a detailed set of instructions to contribute to the community. Deleting and installing all node modules takes much longer, but has the benefit of requiring less effort for the developer. I was short on time, and freshly caffeinated, so this was the best approach for me personally.

The decision was driven by where I was in the development process and the non-technical project requirements I was managing. I didn’t want to risk deleting and reinstalling all modules unless I had no other choice. Even though that approach could solve the error without troubleshooting, it also exposes me to other potential errors. The theme development was more than halfway complete, and it was clear that only imagemin was causing the error. I didn’t want to break gulp just to attempt to fix one module that was only failing at one specific task.

Although I’m not super active in on Discourse, I have notice many people taking the uninstall / reinstall approach as a blanket solution to many issues. One of the things that attracted me to Roots in the first place was the core contributors emphasis on understanding how and why things work. I hope more contributors will start sharing detailed solutions as we continue to grow.

Interesting viewpoint. I’m glad you’re taking the time to understand, that is definitely something that is expected when using Roots tools.

However I feel like I should also play devil’s advocate a bit and look at the other viewpoint. Mostly that vendor packages, IE. npm node_ modules, composer vendor, bower bower_components, one of the benefits is that they are third party code, something you can and should feel comfortable wiping out and getting fresh copies of.

Anyways, that’s just my opinion, but of course nothing wrong with figuring out the actual issue too :thumbsup:

I agree with you @kalenjohnson. It also helps to enables people to experiment and try out new plugins! Sometimes the choosing the best approach simply depends on where you are in your project.