Skip to content
Latchkey

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.

node
Error: spawn /app/node_modules/mozjpeg/vendor/cjpeg ENOENT
    at ChildProcess._handle.onexit (node:internal/child_process)
imagemin-mozjpeg failed to optimize image

Common 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

  1. Reinstall so the vendored binaries are fetched/built for the platform.
Terminal
rm -rf node_modules
npm install --include=optional

Use a runner with the needed libraries

  1. Run optimization on a runner that has the required system libraries preinstalled, or switch to sharp-based optimization.
CI config
# prefer a sharp-based optimizer when native imagemin binaries are fragile

How to prevent it

  • Prefer fewer native image binaries; consolidate on a maintained library like sharp.
  • Pin plugin versions and install with optional dependencies enabled.

Frequently asked questions

What causes "imagemin failed"?
The plugin's vendored binary did not download/build for the runner platform, so the spawn fails with ENOENT.
How do I fix imagemin failed?
Reinstall plugins with optional deps

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card