What are the dependencies of `gatsby-plugin-sharp` and `mozjpeg`?

704 views Asked by At

There's an issue with gatsby-plugin-sharp (or more specifically sub-dependency mozjpeg) whereby it'll give the exception autoreconf: not found, but the issue is actually with other dependencies. There are various posts where people have found one combination or another of various dependencies to get it to work for them (eg https://stackoverflow.com/a/66170062/2475012, https://github.com/gatsbyjs/gatsby/issues/19432#issuecomment-553644600). But there doesn't seem to be a definitive list anywhere of the exact dependencies you need.

I'm running Gatsby on GitHub Actions on ubuntu-latest. My package.json:

{
  "name": "matt.si",
  "private": false,
  "description": "Mattsi Jansky's personal blog",
  "author": "Mattsi Jansky",
  "scripts": {
    "build": "gatsby build",
    "dev": "gatsby develop",
    "test": "jest",
    "test:updateSnapshots": "jest --updateSnapshot",
    "test:visual": "yarn build && ./scripts/run-visual-regression-tests.sh",
    "test:visual:update": "docker-compose run visual-regression-tests reference",
    "test:visual:approve": "docker-compose run visual-regression-tests approve",
    "test:visual:report": "open tests/visual/backstop_data/html_report/index.html",
    "lint": "eslint --ext .js,.jsx --ignore-pattern public ."
  },
  "dependencies": {
    "babel-preset-gatsby": "0.5.1",
    "gatsby": "2.24.87",
    "gatsby-image": "2.4.21",
    "gatsby-plugin-feed": "2.5.19",
    "gatsby-plugin-google-analytics": "2.3.19",
    "gatsby-plugin-manifest": "2.4.35",
    "gatsby-plugin-offline": "3.2.37",
    "gatsby-plugin-react-helmet": "3.3.14",
    "gatsby-plugin-sass": "2.3.21",
    "gatsby-plugin-sharp": "3.0.0",
    "gatsby-remark-footnotes": "0.0.7",
    "gatsby-remark-images": "3.3.39",
    "gatsby-remark-prismjs": "3.5.16",
    "gatsby-source-filesystem": "2.3.36",
    "gatsby-transformer-remark": "2.8.46",
    "gatsby-transformer-sharp": "2.5.20",
    "identity-obj-proxy": "3.0.0",
    "node-sass": "4.14.1",
    "prismjs": "1.22.0",
    "prop-types": "15.7.2",
    "react": "16.14.0",
    "react-dom": "16.14.0",
    "react-helmet": "6.1.0",
    "react-test-renderer": "16.14.0",
    "rehype-react": "6.1.0"
  },
  "devDependencies": {
    "babel-jest": "26.6.1",
    "enzyme": "3.11.0",
    "enzyme-adapter-react-16": "1.15.5",
    "eslint": "7.12.0",
    "eslint-plugin-react": "7.21.5",
    "jest": "26.6.1",
    "wait-on": "5.2.0"
  },
  "license": "GPL-3.0-only"
}

The relevant parts of the GitHub Actions definition:

name: Run tests
on: [push]

jobs:
  build:
    name: Run Tests
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v1
      
      - name: Install System Dependencies
        run: sudo apt-get update && sudo apt-get install make nasm autoconf automake libtool dpkg pkg-config libpng-dev g++

      - name: Install Project Dependencies
        uses: borales/[email protected]
        with:
          cmd: install

It fails with autoreconf: not found at the Install Project Dependencies step. I tried adding autoreconf to the Install System Dependencies step, but it was already the latest version. I tried buildessentials, but it was also already the latest version. I added libvips-dev, which seems to be the name of the libvips library in apt-get, and that one did install. After looking up the same issue with mozjpeg (https://stackoverflow.com/a/64927666/2475012) I added sudo apt-get install make nasm autoconf automake libtool dpkg pkg-config libpng-dev g++. But all of those other than nasm already existed.

But every time I still got the autoreconf: not found issue. Specifically, the full error (https://github.com/Mattsi-Jansky/matt.si/runs/2051073618):

[4/4] Building fresh packages...
error /github/workspace/node_modules/mozjpeg: Command failed.
Exit code: 1
Command: node lib/install.js
Arguments: 
Directory: /github/workspace/node_modules/mozjpeg
Output:
⚠ spawn /github/workspace/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 /github/workspace/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.

So I'm at a loss. I suppose my questions are: a) Am I following the right thread here, trying to find the right dependencies? b) What exactly are the dependencies I should be adding?

2

There are 2 answers

0
Jansky On BEST ANSWER

This was fixed by replacing usages of borales/actions-yarn with setup node, which includes Yarn.

borales/actions-yarn was intended for the GitHub Actions beta, and isn't the recommended way of running yarn actions. They run in some legacy way. I'm not too clear on the details, but I think what was happening was that the borales/actions-yarn was running on a separate image that didn't have the dependencies installed.