Skip to content
Ken Davidson

No exports main resolved ... @babel/helper-compilation-targets/package.json

Gatsby, Node, Github Actions1 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.

Error Message(s)

The following error started happening during the building of my Gatsby site:

1failed Building production JavaScript and CSS bundles - 1.468s
2error Generating JavaScript bundles failed
4[BABEL] /home/runner/work/ No "exports" main resolved in /home/runner/work/
5not finished Generating image thumbnails - 11.907s
6not finished run queries - 1.713s
8npm ERR! errno 1
9npm ERR! build: `gatsby build`
10npm ERR! Exit status 1
11npm ERR!
12npm ERR! Failed at the build script.
13npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
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.log
17##[error]The process '/usr/local/bin/npm' failed with exit code 1

Why for?

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 parallel
3 # This workflow contains a single job called "build"
4 build:
5 # The type of runner on which this job will run
6 runs-on: ubuntu-latest
7 strategy:
8 matrix:
9 node-version: ['12.16.3']
11 # Steps represent a sequence of tasks that will be executed as part of the job
12 # - Checkout gatsby branch
13 # - Update authentication for Github Package Registry @kenjdavidson/base16-scss
14 # - Build gh-pages using action
15 steps:
16 - uses: actions/checkout@v1
17 - name: Use Node.js ${{ matrix.node-version }}
18 uses: actions/setup-node@v1
19 with:
20 node-version: ${{ matrix.node-version }}
21 - name: Authenticate with GitHub package registry
22 run: echo "//${{ secrets.ACCESS_TOKEN }}" > ~/.npmrc
23 - uses: enriikke/gatsby-gh-pages-action@v2
24 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.

Upgrading Node

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.

© 2023 by Ken Davidson. All rights reserved.