Gatsby build failing on mozjpeg Gatsby build failing on mozjpeg docker docker

Gatsby build failing on mozjpeg


According to some GitHub threads:

They suggest to:

  • Installing nasm (highly recommended)
  • If the solution above doesn't work, install automake, autoconf, libtool, dpkg, pkgconfig, libpng, libpng-dev, g++
  • Remove cache


The same issue arises when deploying to to GitLab pages using the docker image: "node:lts-alpine". It fails because yarn:install cannot build mozjpeg.

error /builds/my_project/gatsby/node_modules/mozjpeg: Command failed.

To fix it, add these lines to .gitlab-ci.yml

before_script:   - apk add make nasm autoconf automake libtool dpkg pkgconfig libpng libpng-dev g++

Expected result

[4/4] Building fresh packages...Done in 170.33s.Saving cache for successful job00:27Creating cache master-1...node_modules/: found 82747 matching files and directories WARNING: .cache/: no matching files                WARNING: public/: no matching files                Uploading cache.zip to https://storage.googleapis.com/gitlab-com-runners-cache/project/...Created cacheCleaning up file based variables00:01Job succeeded

Actual result

[4/4] Building fresh packages...error /builds/my_project/gatsby/node_modules/mozjpeg: Command failed.Exit code: 1Command: node lib/install.jsArguments: Directory: /builds/my_project/gatsby/node_modules/mozjpegOutput:⚠ spawn /builds/my_project/gatsby/node_modules/mozjpeg/vendor/cjpeg ENOENT  ⚠ mozjpeg pre-build test failed  ℹ compiling from source  ✖ Error: Command failed: /bin/sh -c autoreconf -fiv/bin/sh: autoreconf: not found    at /builds/my_project/gatsby/node_modules/bin-build/node_modules/execa/index.js:231:11    at runMicrotasks (<anonymous>)    at processTicksAndRejections (internal/process/task_queues.js:93:5)    at async Promise.all (index 0)info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.Cleaning up file based variables00:01ERROR: Job failed: exit code 1

Environment

OS information from: image: "node:lts-alpine"

package.json information:

  npmPackages:    gatsby: ^2.31.1 => 2.31.1    gatsby-image: ^2.10.0 => 2.10.0    gatsby-plugin-manifest: ^2.11.0 => 2.11.0    gatsby-plugin-material-ui: ^2.1.10 => 2.1.10    gatsby-plugin-offline: ^3.9.0 => 3.9.0    gatsby-plugin-react-helmet: ^3.9 => 3.9.0    gatsby-plugin-sharp: ^2.13.4 => 2.13.4    gatsby-source-filesystem: ^2.10.0 => 2.10.0    gatsby-theme-firebase: ^1.0.10 => 1.0.10    gatsby-transformer-sharp: ^2.11.0 => 2.11.0  npmGlobalPackages:    gatsby-cli: 2.17.0


I just went through this same issue on Alpine in a Dockerfile. Turns out that what it needed was everything that you'd typically need to build from source. Alpine has a package called alpine-apk that I added to the Dockerfile. This fixed all subsequent issues that I had with mozjpeg. I realize that the original poster isn't running Alpine but I wanted this to get posted somewhere so that another person with this issue has