— Gatsby, Node, Github Actions — 1 min read
After the recent version of Node was released my Gatsby (as well as others) stopped building on Github. To keep my site up to date (or at least up to date as it can be - I don't post a lot) I use a wonderful Github Action to publish - enriikke/gatsby-gh-pages-action@v2.
The following error started happening during the building of my Gatsby site:
1failed Building production JavaScript and CSS bundles - 1.468s2error Generating JavaScript bundles failed3
4[BABEL] /home/runner/work/kenjdavidson.github.io/kenjdavidson.github.io/.cache/production-app.js: No "exports" main resolved in /home/runner/work/kenjdavidson.github.io/kenjdavidson.github.io/node_modules/@babel/helper-compilation-targets/package.json5not finished Generating image thumbnails - 11.907s6not finished run queries - 1.713s7npm ERR! code ELIFECYCLE8npm ERR! errno 19npm ERR! kenjdavidson.github.io@0.9.0 build: `gatsby build`10npm ERR! Exit status 111npm ERR!12npm ERR! Failed at the kenjdavidson.github.io@0.9.0 build script.13npm ERR! This is probably not a problem with npm. There is likely additional logging output above.14
15npm ERR! A complete log of this run can be found in:16npm ERR! /home/runner/.npm/_logs/2020-08-19T14_12_53_132Z-debug.log17##[error]The process '/usr/local/bin/npm' failed with exit code 1
This was due to the latest version of Node and the @babel/helper-compilation-targets
dependency. The primary way to resolve this was to update the package-lock.json
so that it used the correct dependency versions. But in my mind updating the lock file goes against the whole point of having the lock file. The solution I chose was to update the Github Action to use the appropriate version of Node - until I had time to work through the entire set of dependencies and keeping the project whole.
I updated my Github action to contain the following:
1# A workflow run is made up of one or more jobs that can run sequentially or in parallel2jobs:3 # This workflow contains a single job called "build"4 build:5 # The type of runner on which this job will run6 runs-on: ubuntu-latest7 strategy:8 matrix:9 node-version: ['12.16.3']10
11 # Steps represent a sequence of tasks that will be executed as part of the job12 # - Checkout gatsby branch13 # - Update authentication for Github Package Registry @kenjdavidson/base16-scss14 # - Build gh-pages using action15 steps:16 - uses: actions/checkout@v117 - name: Use Node.js ${{ matrix.node-version }}18 uses: actions/setup-node@v119 with:20 node-version: ${{ matrix.node-version }}21 - name: Authenticate with GitHub package registry22 run: echo "//npm.pkg.github.com/:_authToken=${{ secrets.ACCESS_TOKEN }}" > ~/.npmrc23 - uses: enriikke/gatsby-gh-pages-action@v224 with:25 access-token: ${{ secrets.ACCESS_TOKEN }}
where the key lines are node-version: ['12.16.3]
. Pushing the build version back to the known good version required for these dependencies resolved the issue and allowed my site to once again be published.
Once I get a chance to upgrade Node on my personal machine, I'll be able to get the package.json
dependencies to match the updated Node version - but from now on I'll probably try to keep this Action using the same build that matches the Gatsby requirement.