How to fix the Netlify GLIBC build error with Node.js v18
I maintain one static website, built with webpack and deployed on Netlify, which was an easy candidate to see if node v18 introduced any bugs in our build and deploy process.
In the Netlify site settings, I changed the
NODE_VERSION environment variable to
18 and triggered a deploy, which failed. Here’s the log:
3:00:43 PM: Build ready to start 3:00:51 PM: build-image version: ac716c5be7f79fe384a0f3759e8ef612cb821a37 (xenial) 3:00:51 PM: build-image tag: v3.13.0 3:00:51 PM: buildbot version: e58b6be665675c0f99b33132a8c1eec1f775eba1 3:00:51 PM: Building without cache 3:00:51 PM: Starting to prepare the repo for build 3:00:51 PM: No cached dependencies found. Cloning fresh repo 3:00:51 PM: git clone [REDACTED] 3:00:54 PM: Preparing Git Reference refs/heads/master 3:00:55 PM: Parsing package.json dependencies 3:00:56 PM: Starting build script 3:00:56 PM: Installing dependencies 3:00:56 PM: Python version set to 2.7 3:00:57 PM: Downloading and installing node v18.0.0... 3:00:57 PM: Downloading https://nodejs.org/dist/v18.0.0/node-v18.0.0-linux-x64.tar.xz... 3:00:58 PM: Computing checksum with sha256sum 3:00:58 PM: Checksums matched! 3:01:00 PM: node: /lib/x86_64-linux-gnu/libm.so.6: version `GLIBC_2.27' not found (required by node) node: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.25' not found (required by node) node: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.28' not found (required by node) nvm is not compatible with the npm config "prefix" option: currently set to "" 3:01:00 PM: Run `nvm use --delete-prefix v18.0.0` to unset it. 3:01:00 PM: Failed to install node version '18' 3:01:00 PM: Build was terminated: Build script returned non-zero exit code: 1 3:01:01 PM: Creating deploy upload records 3:01:01 PM: Failing build: Failed to build site 3:01:01 PM: Failed during stage 'building site': Build script returned non-zero exit code: 1 (https://ntl.fyi/exit-code-1) 3:01:01 PM: Finished processing build request in 10.203136084s
Clearing the cache and retrying the deploy yielded the same result.
Since Netlify uses
nvm to manage node versions, I wondered what was wrong with the build environment. As can be seen in the logs, the build environment was still running Ubuntu Xenial (16.04), which is no longer actively maintained.
Thankfully, Netlify allows you to select Ubuntu Focal (20.04). To do so, navigate to Site settings > Build & deploy > Continuous Deployment > Build image selection.
I cleared the cache and it built and deployed perfectly this time.
Sometimes the build environment needs an update too!