Skip to content

Instantly share code, notes, and snippets.

@welcoMattic
Last active August 15, 2024 15:58
Show Gist options
  • Save welcoMattic/9f0991fa81a80096a3877ee42562c504 to your computer and use it in GitHub Desktop.
Save welcoMattic/9f0991fa81a80096a3877ee42562c504 to your computer and use it in GitHub Desktop.
How to fix `Error: spawn ./node_modules/jpegtran-bin/vendor/jpegtran ENOENT` error for imagemin

If you're trying to run imagemin (from grunt or gulp or anything else) on Alpine, you certainly had to meet this error :

Error: spawn /YOUR_PROJECT_PATH/node_modules/jpegtran-bin/vendor/jpegtran ENOENT or the same with optipng or gifsicle instead of jpegtran.

Here's how to solve it.

First you need to install on Alpine missing package used to compile jpegtran, gifsicle and optipng binaries. Those packages are (at least):

autoconf automake file build-base nasm musl libpng-dev zlib-dev

Now, rebuild your container.

And then, remove your node_module directory, and run npm install or yarn command.

Enjoy 🎉

Note: this workaround works like a charm for me, please comment here if your meet other issues ;)

@maiconzucco
Copy link

Hi,

I solved the issue with the command below:
npm rebuild jpegtran-bin

@mhdiriansyah
Copy link

thanks..!!
it's works

@jnaklaas
Copy link

Thanks, worked for me too using the yarn equivalent:

yarn add --force jpegtran-bin

@jasperf
Copy link

jasperf commented Nov 4, 2019

@jnaklaas that really helped me. Got stuck running yarn build:production for my Sage setup. Regular dev build worked but production build choked spitting out

$ webpack --env.production --progress --config resources/assets/build/webpack.config.js
 94% asset optimizationError: spawn /Users/jasper/code/alarsite/wp-content/themes/alar/node_modules/jpegtran-bin/vendor/jpegtran ENOENT
    at Process.ChildProcess._handle.onexit (internal/child_process.js:240:19)
    at onErrorNT (internal/child_process.js:415:16)
    at process._tickCallback (internal/process/next_tick.js:63:19)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Your yarn add --force jpegtran-bin did the trick. New package-lock.json generation is still wise though:

warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json.

@jasperf
Copy link

jasperf commented Nov 4, 2019

Hmm never mind. That was related to using two ore more tools for package management. My bad.

@kaizendeveloper
Copy link

Added

autoconf automake file build-base nasm musl libpng-dev zlib-dev

and it worked!

@sundeepgupta
Copy link

npm rebuild jpegtran-bin

Worked for me 🙏

@fishtankmike
Copy link

npm rebuild jpegtran-bin

This worked for me too, thanks!

@thiagorossener
Copy link

thiagorossener commented May 10, 2021

npm rebuild jpegtran-bin

Thank you! It worked perfectly!

@SiavashEXE
Copy link

Hi,

I solved the issue with the command below:
npm rebuild jpegtran-bin

Thanks man! it worked perfectly!

@fintinc
Copy link

fintinc commented Feb 15, 2022

npm rebuild jpegtran-bin

Works – Thanks!

@91ranjan
Copy link

Worked for me too. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment