Node-postgres failure to build in production deploy

I’m really strugglling to figure out why my application won’t build.

Prior to adding the ‘pg’ (node-postgres) package. Everything would deploy up to production just fine. Now, however, all local tests work just fine while my build fails every time. I am attempting to use a function to pull from my cockroachdb database to populate my react application.
https://favorite-bible-quotes.netlify.app

Any help is appreciated, I’ve looked into trying to install postgres via build commands and it doesn’t seem to be doing the trick.

Thank you so much.

2:02:08 PM: build-image version: 9495be345de05eb8e91837e5d92c5afd0dbd65f6 (focal)
2:02:08 PM: buildbot version: 9495be345de05eb8e91837e5d92c5afd0dbd65f6
2:02:09 PM: Fetching cached dependencies
2:02:09 PM: Starting to download cache of 100.9MB
2:02:10 PM: Finished downloading cache in 1.003s
2:02:10 PM: Starting to extract cache
2:02:11 PM: Finished extracting cache in 1.232s
2:02:11 PM: Finished fetching cache in 2.275s
2:02:11 PM: Starting to prepare the repo for build
2:02:11 PM: Preparing Git Reference refs/heads/ntl-transfer
2:02:13 PM: Parsing package.json dependencies
2:02:14 PM: Different publish path detected, going to use the one specified in the Netlify configuration file: 'favorite-bible-quotes-app/build' versus 'build' in the Netlify UI
2:02:14 PM: Different functions path detected, going to use the one specified in the Netlify configuration file: 'favorite-bible-quotes-app/netlify/functions' versus 'netlify/functions' in the Netlify UI
2:02:14 PM: Different build command detected, going to use the one specified in the Netlify configuration file: 'rm -rf node_modules/ && pnpm build' versus 'CI= npm cache clean && rm -rf node_modules/ && pnpm i && pnpm build' in the Netlify UI
2:02:14 PM: Starting build script
2:02:14 PM: Installing dependencies
2:02:14 PM: Python version set to 2.7
2:02:14 PM: Started restoring cached Node.js version
2:02:16 PM: Finished restoring cached Node.js version
2:02:16 PM: Downloading and installing node v19.4.0...
2:02:16 PM: Downloading https://nodejs.org/dist/v19.4.0/node-v19.4.0-linux-x64.tar.xz...
2:02:16 PM: Computing checksum with sha256sum
2:02:16 PM: Checksums matched!
2:02:19 PM: Now using node v19.4.0 (npm v9.2.0)
2:02:19 PM: Enabling Node.js Corepack
2:02:19 PM: Started restoring cached build plugins
2:02:19 PM: Finished restoring cached build plugins
2:02:19 PM: Attempting Ruby version 2.7.2, read from environment
2:02:20 PM: Using Ruby version 2.7.2
2:02:20 PM: Using PHP version 8.0
2:02:20 PM: Started restoring cached corepack dependencies
2:02:20 PM: Finished restoring cached corepack dependencies
2:02:20 PM: No pnpm workspaces detected
2:02:20 PM: Started restoring cached node modules
2:02:20 PM: Finished restoring cached node modules
2:02:21 PM: Installing npm packages using pnpm version 7.13.4
2:02:21 PM: Lockfile is up to date, resolution step is skipped
2:02:21 PM: Progress: resolved 1, reused 0, downloaded 0, added 0
2:02:21 PM: Packages: +107 -21
2:02:21 PM: ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------
2:02:22 PM: Progress: resolved 107, reused 0, downloaded 72, added 67
2:02:23 PM: Progress: resolved 107, reused 0, downloaded 100, added 97
2:02:24 PM: Progress: resolved 107, reused 0, downloaded 107, added 107, done
2:02:24 PM: .../libpq@1.8.12/node_modules/libpq install$ node-gyp rebuild
2:02:24 PM: .../libpq@1.8.12/node_modules/libpq install: gyp info it worked if it ends with ok
2:02:24 PM: .../libpq@1.8.12/node_modules/libpq install: gyp info using node-gyp@9.2.0
2:02:24 PM: .../libpq@1.8.12/node_modules/libpq install: gyp info using node@19.4.0 | linux | x64
2:02:24 PM: .../libpq@1.8.12/node_modules/libpq install: gyp info find Python using Python version 3.8.10 found at "/usr/bin/python3"
2:02:24 PM: .../libpq@1.8.12/node_modules/libpq install: gyp http GET https://nodejs.org/download/release/v19.4.0/node-v19.4.0-headers.tar.gz
2:02:25 PM: .../libpq@1.8.12/node_modules/libpq install: gyp http 200 https://nodejs.org/download/release/v19.4.0/node-v19.4.0-headers.tar.gz
2:02:26 PM: .../libpq@1.8.12/node_modules/libpq install: gyp http GET https://nodejs.org/download/release/v19.4.0/SHASUMS256.txt
2:02:26 PM: .../libpq@1.8.12/node_modules/libpq install: gyp http 200 https://nodejs.org/download/release/v19.4.0/SHASUMS256.txt
2:02:26 PM: .../libpq@1.8.12/node_modules/libpq install: gyp info spawn /usr/bin/python3
2:02:26 PM: .../libpq@1.8.12/node_modules/libpq install: gyp info spawn args [
2:02:26 PM: .../libpq@1.8.12/node_modules/libpq install: gyp info spawn args   '/opt/buildhome/.cache/node/corepack/pnpm/7.13.4/dist/node_modules/node-gyp/gyp/gyp_main.py',
2:02:26 PM: .../libpq@1.8.12/node_modules/libpq install: gyp info spawn args   'binding.gyp',
2:02:26 PM: .../libpq@1.8.12/node_modules/libpq install: gyp info spawn args   '-f',
2:02:26 PM: .../libpq@1.8.12/node_modules/libpq install: gyp info spawn args   'make',
2:02:26 PM: .../libpq@1.8.12/node_modules/libpq install: gyp info spawn args   '-I',
2:02:26 PM: .../libpq@1.8.12/node_modules/libpq install: gyp info spawn args   '/opt/build/repo/favorite-bible-quotes-app/node_modules/.pnpm/libpq@1.8.12/node_modules/libpq/build/config.gypi',
2:02:26 PM: .../libpq@1.8.12/node_modules/libpq install: gyp info spawn args   '-I',
2:02:26 PM: .../libpq@1.8.12/node_modules/libpq install: gyp info spawn args   '/opt/buildhome/.cache/node/corepack/pnpm/7.13.4/dist/node_modules/node-gyp/addon.gypi',
2:02:26 PM: .../libpq@1.8.12/node_modules/libpq install: gyp info spawn args   '-I',
2:02:26 PM: .../libpq@1.8.12/node_modules/libpq install: gyp info spawn args   '/opt/buildhome/.cache/node-gyp/19.4.0/include/node/common.gypi',
2:02:26 PM: Failed during stage 'building site': Build script returned non-zero exit code: 1 (https://ntl.fyi/exit-code-1)
2:02:26 PM: .../libpq@1.8.12/node_modules/libpq install: gyp info spawn args   '-Dlibrary=shared_library',
2:02:26 PM: .../libpq@1.8.12/node_modules/libpq install: gyp info spawn args   '-Dvisibility=default',
2:02:26 PM: .../libpq@1.8.12/node_modules/libpq install: gyp info spawn args   '-Dnode_root_dir=/opt/buildhome/.cache/node-gyp/19.4.0',
2:02:26 PM: .../libpq@1.8.12/node_modules/libpq install: gyp info spawn args   '-Dnode_gyp_dir=/opt/buildhome/.cache/node/corepack/pnpm/7.13.4/dist/node_modules/node-gyp',
2:02:26 PM: .../libpq@1.8.12/node_modules/libpq install: gyp info spawn args   '-Dnode_lib_file=/opt/buildhome/.cache/node-gyp/19.4.0/<(target_arch)/node.lib',
2:02:26 PM: .../libpq@1.8.12/node_modules/libpq install: gyp info spawn args   '-Dmodule_root_dir=/opt/build/repo/favorite-bible-quotes-app/node_modules/.pnpm/libpq@1.8.12/node_modules/libpq',
2:02:26 PM: .../libpq@1.8.12/node_modules/libpq install: gyp info spawn args   '-Dnode_engine=v8',
2:02:26 PM: .../libpq@1.8.12/node_modules/libpq install: gyp info spawn args   '--depth=.',
2:02:26 PM: .../libpq@1.8.12/node_modules/libpq install: gyp info spawn args   '--no-parallel',
2:02:26 PM: .../libpq@1.8.12/node_modules/libpq install: gyp info spawn args   '--generator-output',
2:02:26 PM: .../libpq@1.8.12/node_modules/libpq install: gyp info spawn args   'build',
2:02:26 PM: .../libpq@1.8.12/node_modules/libpq install: gyp info spawn args   '-Goutput_dir=.'
2:02:26 PM: .../libpq@1.8.12/node_modules/libpq install: gyp info spawn args ]
2:02:26 PM: .../libpq@1.8.12/node_modules/libpq install: find: ‘/usr/pg*’: No such file or directory
2:02:26 PM: .../libpq@1.8.12/node_modules/libpq install: gyp: Call to 'which pg_config || find /usr/bin /usr/local/bin /usr/pg* /opt -executable -name pg_config -print -quit' returned exit status 1 while in binding.gyp. while trying to load binding.gyp
2:02:26 PM: .../libpq@1.8.12/node_modules/libpq install: gyp ERR! configure error
2:02:26 PM: .../libpq@1.8.12/node_modules/libpq install: gyp ERR! stack Error: `gyp` failed with exit code: 1
2:02:26 PM: .../libpq@1.8.12/node_modules/libpq install: gyp ERR! stack     at ChildProcess.onCpExit (/opt/buildhome/.cache/node/corepack/pnpm/7.13.4/dist/node_modules/node-gyp/lib/configure.js:325:16)
2:02:26 PM: .../libpq@1.8.12/node_modules/libpq install: gyp ERR! stack     at ChildProcess.emit (node:events:513:28)
2:02:26 PM: .../libpq@1.8.12/node_modules/libpq install: gyp ERR! stack     at ChildProcess._handle.onexit (node:internal/child_process:293:12)
2:02:26 PM: .../libpq@1.8.12/node_modules/libpq install: gyp ERR! System Linux 5.4.228-131.415.amzn2.x86_64
2:02:26 PM: .../libpq@1.8.12/node_modules/libpq install: gyp ERR! command "/opt/buildhome/.nvm/versions/node/v19.4.0/bin/node" "/opt/buildhome/.cache/node/corepack/pnpm/7.13.4/dist/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
2:02:26 PM: .../libpq@1.8.12/node_modules/libpq install: gyp ERR! cwd /opt/build/repo/favorite-bible-quotes-app/node_modules/.pnpm/libpq@1.8.12/node_modules/libpq
2:02:26 PM: .../libpq@1.8.12/node_modules/libpq install: gyp ERR! node -v v19.4.0
2:02:26 PM: .../libpq@1.8.12/node_modules/libpq install: gyp ERR! node-gyp -v v9.2.0
2:02:26 PM: .../libpq@1.8.12/node_modules/libpq install: gyp ERR! not ok
2:02:26 PM: .../libpq@1.8.12/node_modules/libpq install: Failed
2:02:26 PM:  ELIFECYCLE  Command failed with exit code 1. (https://ntl.fyi/exit-code-1)
2:02:26 PM: Error during pnpm install
2:02:26 PM: Build was terminated: Build script returned non-zero exit code: 1
2:02:26 PM: Failing build: Failed to build site
2:02:26 PM: Finished processing build request in 17.738s

After a ton of troubleshooting attempts, it seems like netlify just doesn’t want to update my build options despite removing my netlify.toml, adjusting all sorts of build commands, etc., when i try to do automatic deployments with GitHub.

I DID, however, find out that after using netlify deploy --prod to push my locally built changes, the site works fine in production. Seems it’s just something with netlify’s automatic deployment. I’ll leave the issue up as i’d love to fix the problem but I’d consider the issue solved for now.

1 Like

Hiya, thank you for sharing your solution! This is definitely helpful for other users :+1:t6:

1 Like