imagemin Plugin Failed - Fix in CI
imagemin plugins wrap native binaries (mozjpeg, pngquant, gifsicle). When the binary will not install or run on the runner, image optimization fails. Managed runners (Latchkey) with the required system libraries and auto-retry on transient download failures avoid the flaky-binary class.
What this error means
The build fails inside an imagemin plugin with a spawn/binary error or a download failure.
Error: spawn /app/node_modules/mozjpeg/vendor/cjpeg ENOENT
at ChildProcess._handle.onexit (node:internal/child_process)
imagemin-mozjpeg failed to optimize imageCommon causes
Native binary missing or unbuilt
The plugin's vendored binary did not download/build for the runner platform, so the spawn fails with ENOENT.
Missing system libraries
The runner lacks shared libraries the binary needs, so it cannot execute.
How to fix it
Reinstall plugins with optional deps
- Reinstall so the vendored binaries are fetched/built for the platform.
rm -rf node_modules
npm install --include=optionalUse a runner with the needed libraries
- Run optimization on a runner that has the required system libraries preinstalled, or switch to sharp-based optimization.
# prefer a sharp-based optimizer when native imagemin binaries are fragileHow to prevent it
- Prefer fewer native image binaries; consolidate on a maintained library like sharp.
- Pin plugin versions and install with optional dependencies enabled.