Skip to content
Latchkey

Gatsby "Generating image thumbnails failed" (sharp) in CI

gatsby-plugin-image and gatsby-transformer-sharp use the native sharp library to process images. When sharp's prebuilt binary does not match the runner platform or libc, image generation throws and the build fails.

What this error means

The build errors during image processing with "Something went wrong installing the \"sharp\" module" or "Generating image thumbnails failed", often mentioning a missing .node binary or a glibc/musl mismatch.

gatsby
Something went wrong installing the "sharp" module

Cannot find module '../build/Release/sharp-linux-x64.node'
Possible solutions: ... npm install --platform=linux --arch=x64 sharp

Common causes

A cached or wrong-platform sharp binary

A node_modules cache built on a different OS/arch (or a musl image like Alpine) restored a sharp binary that does not load on the runner.

A partial or offline install of optional binaries

sharp downloads a platform binary at install; a blocked network or --no-optional install leaves it without one.

How to fix it

Reinstall sharp for the runner platform

  1. Do a clean install so optional native binaries download for this OS/arch.
  2. Avoid restoring a node_modules cache built on a different platform.
  3. On Alpine, install the musl build explicitly.
Terminal
npm install --include=optional sharp
# Alpine: npm install --os=linux --libc=musl --cpu=x64 sharp

Cache the package download, not node_modules

Let setup-node cache the npm download directory so each platform resolves its own sharp binary.

.github/workflows/ci.yml
- uses: actions/setup-node@v4
  with:
    node-version: '20'
    cache: 'npm'

How to prevent it

  • Never restore node_modules built on a different OS or libc.
  • Use --include=optional so sharp gets its platform binary.
  • Match the runner image (glibc vs musl) to the sharp build you install.

Frequently asked questions

What causes ""Generating image thumbnails failed""?
A node_modules cache built on a different OS/arch (or a musl image like Alpine) restored a sharp binary that does not load on the runner.
How do I fix "Generating image thumbnails failed"?
Reinstall sharp for the runner platform

Related guides

References

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