Build error: Can't build node_modules/sharp

I’m trying to build the Production version of my site and the build is failing, which is weird because a different branch (staging), with the exact same code, builds perfectly. The only difference I can see in the build scripts is that my staging branch is building from a cache and the production branch is building fresh.

My site id is: optimistic-kepler-83d60b

And here’s my build log. Any idea what I’m doing wrong?

12:53:03 PM: Waiting for other deploys from your team to complete. Check the queue:
12:53:07 PM: Build ready to start
12:53:09 PM: build-image version: d2c6dbeac570350a387d832f64bc980dc964ad65 (focal)
12:53:09 PM: build-image tag: v4.8.0
12:53:09 PM: buildbot version: e552b142336b2b1222a93a4fd4cbed0019c77b46
12:53:09 PM: Fetching cached dependencies
12:53:09 PM: Failed to fetch cache, continuing with build
12:53:09 PM: Starting to prepare the repo for build
12:53:10 PM: No cached dependencies found. Cloning fresh repo
12:53:10 PM: git clone github.com/nitidbit/adol-health
12:53:13 PM: Preparing Git Reference refs/heads/production
12:53:13 PM: Parsing package.json dependencies
12:53:14 PM: Starting build script
12:53:14 PM: Installing dependencies
12:53:14 PM: Python version set to 2.7
12:53:15 PM: Attempting node version ‘16.14.2’ from .node-version
12:53:15 PM: v16.14.2 is already installed.
12:53:15 PM: Now using node v16.14.2 (npm v8.5.0)
12:53:16 PM: Started restoring cached build plugins
12:53:16 PM: Finished restoring cached build plugins
12:53:16 PM: Attempting ruby version 2.7.2, read from environment
12:53:17 PM: Using ruby version 2.7.2
12:53:17 PM: Using PHP version 8.0
12:53:18 PM: No npm workspaces detected
12:53:18 PM: Started restoring cached node modules
12:53:18 PM: Finished restoring cached node modules
12:53:18 PM: Installing NPM modules using NPM version 8.5.0
12:54:39 PM: npm ERR! code 1
12:54:39 PM: npm ERR! path /opt/build/repo/node_modules/sharp
12:54:39 PM: npm ERR! command failed
12:54:39 PM: npm ERR! command sh -c node-gyp rebuild
12:54:39 PM: npm ERR! make: Entering directory ‘/opt/build/repo/node_modules/sharp/build’
12:54:39 PM: Creating deploy upload records
12:54:39 PM: npm ERR! CC(target) Release/obj.target/nothing/…/node-addon-api/nothing.o
12:54:39 PM: npm ERR! AR(target) Release/obj.target/…/node-addon-api/nothing.a
12:54:39 PM: npm ERR! COPY Release/nothing.a
12:54:39 PM: npm ERR! TOUCH Release/obj.target/libvips-cpp.stamp
12:54:39 PM: npm ERR! CXX(target) Release/obj.target/sharp-linux-x64/src/common.o
12:54:39 PM: npm ERR! make: Leaving directory ‘/opt/build/repo/node_modules/sharp/build’
12:54:40 PM: Failed during stage ‘building site’: Build script returned non-zero exit code: 1 (redacted)
12:54:39 PM: npm ERR! gyp info it worked if it ends with ok
12:54:39 PM: npm ERR! gyp info using node-gyp@7.1.2
12:54:39 PM: npm ERR! gyp info using node@16.14.2 | linux | x64
12:54:39 PM: npm ERR! gyp info find Python using Python version 3.8.10 found at “/usr/bin/python3”
12:54:39 PM: npm ERR! gyp http GET https://nodejs.org/download/release/v16.14.2/node-v16.14.2-headers.tar.gz
12:54:39 PM: npm ERR! gyp http 200 https://nodejs.org/download/release/v16.14.2/node-v16.14.2-headers.tar.gz
12:54:39 PM: npm ERR! gyp http GET https://nodejs.org/download/release/v16.14.2/SHASUMS256.txt
12:54:39 PM: npm ERR! gyp http 200 https://nodejs.org/download/release/v16.14.2/SHASUMS256.txt
12:54:39 PM: npm ERR! (node:1256) [DEP0150] DeprecationWarning: Setting process.config is deprecated. In the future the property will be read-only.
12:54:39 PM: npm ERR! (Use node --trace-deprecation ... to show where the warning was created)
12:54:39 PM: npm ERR! gyp info spawn /usr/bin/python3
12:54:39 PM: npm ERR! gyp info spawn args [
12:54:39 PM: npm ERR! gyp info spawn args ‘/opt/build/repo/node_modules/node-gyp/gyp/gyp_main.py’,
12:54:39 PM: npm ERR! gyp info spawn args ‘binding.gyp’,
12:54:39 PM: npm ERR! gyp info spawn args ‘-f’,
12:54:39 PM: npm ERR! gyp info spawn args ‘make’,
12:54:39 PM: npm ERR! gyp info spawn args ‘-I’,
12:54:39 PM: npm ERR! gyp info spawn args ‘/opt/build/repo/node_modules/sharp/build/config.gypi’,
12:54:39 PM: npm ERR! gyp info spawn args ‘-I’,
12:54:39 PM: npm ERR! gyp info spawn args ‘/opt/build/repo/node_modules/node-gyp/addon.gypi’,
12:54:39 PM: npm ERR! gyp info spawn args ‘-I’,
12:54:39 PM: npm ERR! gyp info spawn args ‘/opt/buildhome/.cache/node-gyp/16.14.2/include/node/common.gypi’,
12:54:39 PM: npm ERR! gyp info spawn args ‘-Dlibrary=shared_library’,
12:54:39 PM: npm ERR! gyp info spawn args ‘-Dvisibility=default’,
12:54:39 PM: npm ERR! gyp info spawn args ‘-Dnode_root_dir=/opt/buildhome/.cache/node-gyp/16.14.2’,
12:54:39 PM: npm ERR! gyp info spawn args ‘-Dnode_gyp_dir=/opt/build/repo/node_modules/node-gyp’,
12:54:39 PM: npm ERR! gyp info spawn args ‘-Dnode_lib_file=/opt/buildhome/.cache/node-gyp/16.14.2/<(target_arch)/node.lib’,
12:54:39 PM: npm ERR! gyp info spawn args ‘-Dmodule_root_dir=/opt/build/repo/node_modules/sharp’,
12:54:39 PM: npm ERR! gyp info spawn args ‘-Dnode_engine=v8’,
12:54:39 PM: npm ERR! gyp info spawn args ‘–depth=.’,
12:54:39 PM: npm ERR! gyp info spawn args ‘–no-parallel’,
12:54:39 PM: npm ERR! gyp info spawn args ‘–generator-output’,
12:54:39 PM: npm ERR! gyp info spawn args ‘build’,
12:54:39 PM: npm ERR! gyp info spawn args ‘-Goutput_dir=.’
12:54:39 PM: npm ERR! gyp info spawn args ]
12:54:39 PM: npm ERR! gyp info spawn make
12:54:39 PM: npm ERR! gyp info spawn args [ ‘BUILDTYPE=Release’, ‘-C’, ‘build’ ]
12:54:39 PM: npm ERR! In file included from …/src/common.cc:24:
12:54:39 PM: npm ERR! /usr/include/vips/vips8:35:10: fatal error: glib-object.h: No such file or directory
12:54:39 PM: npm ERR! 35 | #include <glib-object.h>
12:54:39 PM: npm ERR! | ^~~~~~~~~~~~~~~
12:54:39 PM: npm ERR! compilation terminated.
12:54:39 PM: npm ERR! make: *** [sharp-linux-x64.target.mk:139: Release/obj.target/sharp-linux-x64/src/common.o] Error 1
12:54:39 PM: npm ERR! gyp ERR! build error
12:54:39 PM: npm ERR! gyp ERR! stack Error: make failed with exit code: 2
12:54:39 PM: npm ERR! gyp ERR! stack at ChildProcess.onExit (/opt/build/repo/node_modules/node-gyp/lib/build.js:194:23)
12:54:39 PM: npm ERR! gyp ERR! stack at ChildProcess.emit (node:events:526:28)
12:54:39 PM: npm ERR! gyp ERR! stack at Process.ChildProcess._handle.onexit (node:internal/child_process:291:12)
12:54:39 PM: npm ERR! gyp ERR! System Linux 5.4.149-73.259.amzn2.x86_64
12:54:39 PM: npm ERR! gyp ERR! command “/opt/buildhome/.nvm/versions/node/v16.14.2/bin/node” “/opt/build/repo/node_modules/.bin/node-gyp” “rebuild”
12:54:39 PM: npm ERR! gyp ERR! cwd /opt/build/repo/node_modules/sharp
12:54:39 PM: npm ERR! gyp ERR! node -v v16.14.2
12:54:39 PM: npm ERR! gyp ERR! node-gyp -v v7.1.2
12:54:39 PM: npm ERR! gyp ERR! not ok
12:54:39 PM: npm ERR! A complete log of this run can be found in:
12:54:39 PM: npm ERR! /opt/buildhome/.npm/_logs/2022-04-15T19_53_19_015Z-debug-0.log
12:54:39 PM: Error during NPM install
12:54:39 PM: Build was terminated: Build script returned non-zero exit code: 1
12:54:40 PM: Failing build: Failed to build site
12:54:40 PM: Finished processing build request in 1m30.819218037s

Hey @132a94c666188b89944b

Do both branches have the same dependencies, including the same versions of them? It would appear there is an incompatible dependency, possibly one requiring an earlier Node.js version, which is why it is attempting to do a rebuild.

They are at the exact same commit in git. Production (the build that’s broken) is the main branch for our site, and Staging (the one that works) is a branch deploy on the same site.

The only thing that seems different is that Staging is building from cache. I’m scared to remove the cache because then perhaps neither will build.

Try using Node 14 for your site.

1 Like

Oh, that totally worked. Huh, wonder why I don’t have to use node 14 on my other identical branch/site. Mysterious, but thanks for the tip!

1 Like

Thanks for coming back and letting us know that worked. Happy building! :rocket: