Failed to load next.config.js in GitHub Action

Recently I updated my blog to the latest Next.js 12.1, which has been released recently. Locally, running next build still worked fine. However, my GitHub Actions started to fail with the message "Failed to load next.config.js".

Error output saying: Failed to load next.config.js

After searching and finding this issue on GitHub, it was clear that there seemed to be an issue with the Node version, as Next.js requires at least Node.js 12.22.0 or later. Luckily, the setup-node action, provides the possibility to specify the node-version which should be used. By default it uses the node version from PATH. This was v10.24.1 in my case.

I could resolve my issue by specifying at least a fixed major version like that:

- name: Install and Build
  uses: actions/setup-node@v2
  with:
    node-version: "16"