Unable to publish function using postgres

Unable to deploy this:
postgres function

If I remove pg dependencies, it works:

   "pg": "^7.4.1",
   "pg-native": "^2.2.0",

I also try to run it with node 12.10.0 and new pg version, it gives me the same
Gives

5:32:35 PM: [1/4] Resolving packages...
5:32:36 PM: [2/4] Fetching packages...
5:32:51 PM: info fsevents@1.1.2: The platform "linux" is incompatible with this module.
5:32:51 PM: info "fsevents@1.1.2" is an optional dependency and failed compatibility check. Excluding it from installation.
5:32:51 PM: info fsevents@1.1.3: The platform "linux" is incompatible with this module.
5:32:51 PM: info "fsevents@1.1.3" is an optional dependency and failed compatibility check. Excluding it from installation.
5:32:51 PM: [3/4] Linking dependencies...
5:32:58 PM: [4/4] Building fresh packages...
5:33:00 PM: error /opt/build/repo/node_modules/libpq: Command failed.
5:33:00 PM: Exit code: 1
5:33:00 PM: Command: node-gyp rebuild
5:33:00 PM: Arguments:
5:33:00 PM: Directory: /opt/build/repo/node_modules/libpq
5:33:00 PM: Output:
5:33:00 PM: gyp info it worked if it ends with ok
5:33:00 PM: gyp info using node-gyp@5.1.0
5:33:00 PM: failed during stage 'building site': Build script returned non-zero exit code: 1
5:33:00 PM: gyp info using node@10.20.1 | linux | x64
5:33:00 PM: gyp info find Python using Python version 2.7.12 found at "/opt/buildhome/python2.7/bin/python"
5:33:00 PM: gyp http GET https://nodejs.org/download/release/v10.20.1/node-v10.20.1-headers.tar.gz
5:33:00 PM: Shutting down logging, 44 messages pending

Hi @stephen.zambaux,

Thanks for reporting this.

This appears to be a bug in libpq.
A workaround for this issue seems to be to install postgresql-dev.

The full log of the build (which was truncated due to a separate issue with logging) is:

gyp info it worked if it ends with ok
gyp info using node-gyp@5.1.0
gyp info using node@10.20.1 | linux | x64
gyp info find Python using Python version 2.7.12 found at "/opt/buildhome/python2.7/bin/python"
gyp http GET https://nodejs.org/download/release/v10.20.1/node-v10.20.1-headers.tar.gz
gyp http 200 https://nodejs.org/download/release/v10.20.1/node-v10.20.1-headers.tar.gz
gyp http GET https://nodejs.org/download/release/v10.20.1/SHASUMS256.txt
gyp http 200 https://nodejs.org/download/release/v10.20.1/SHASUMS256.txt
gyp info spawn /opt/buildhome/python2.7/bin/python
gyp info spawn args [ '/opt/buildhome/.nvm/versions/node/v10.20.1/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py',
gyp info spawn args 'binding.gyp',
gyp info spawn args '-f',
gyp info spawn args 'make',
gyp info spawn args '-I',
gyp info spawn args '/opt/build/repo/node_modules/libpq/build/config.gypi',
gyp info spawn args '-I',
gyp info spawn args '/opt/buildhome/.nvm/versions/node/v10.20.1/lib/node_modules/npm/node_modules/node-gyp/addon.gypi',
gyp info spawn args '-I',
gyp info spawn args '/opt/buildhome/.cache/node-gyp/10.20.1/include/node/common.gypi',
gyp info spawn args '-Dlibrary=shared_library',
gyp info spawn args '-Dvisibility=default',
gyp info spawn args '-Dnode_root_dir=/opt/buildhome/.cache/node-gyp/10.20.1',
gyp info spawn args '-Dnode_gyp_dir=/opt/buildhome/.nvm/versions/node/v10.20.1/lib/node_modules/npm/node_modules/node-gyp',
gyp info spawn args '-Dnode_lib_file=/opt/buildhome/.cache/node-gyp/10.20.1/<(target_arch)/node.lib',
gyp info spawn args '-Dmodule_root_dir=/opt/build/repo/node_modules/libpq',
gyp info spawn args '-Dnode_engine=v8',
gyp info spawn args '--depth=.',
gyp info spawn args '--no-parallel',
gyp info spawn args '--generator-output',
gyp info spawn args 'build',
gyp info spawn args '-Goutput_dir=.' ]
find: ‘/usr/pg*’: No such file or directory
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
gyp ERR! configure error
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack at ChildProcess.onCpExit (/opt/buildhome/.nvm/versions/node/v10.20.1/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:351:16)
gyp ERR! stack at ChildProcess.emit (events.js:198:13)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:248:12)
gyp ERR! System Linux 4.14.138+
gyp ERR! command "/opt/buildhome/.nvm/versions/node/v10.20.1/bin/node" "/opt/buildhome/.nvm/versions/node/v10.20.1/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /opt/build/repo/node_modules/libpq
gyp ERR! node -v v10.20.1
gyp ERR! node-gyp -v v5.1.0
gyp ERR! not ok
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
Error during Yarn install
Error running command: Build script returned non-zero exit code: 1

As you can see the following line tries to find some files in /usr/pg* but none exist.

Thank you,

should I try to add apk add before the build cmd?

The CI environment is based on Ubuntu not Alpine, so apt-get should be used instead of apk. However apt-get requires sudo which is not available in user mode. However adding a specific apt-get can be requested to our build-image.

That being said, it appears that the core problem is actually a bug in node-libpq. Since a bug was opened in their GitHub repository, I think this is probably where you might get your best chances to solve your issue unfortunately. However I opened a GitHub issue in our build-image to see if someone else has an idea on how to work around that bug.

Thx,

This fix the build locally, I did a pull request with it:

Pull Request

How can I use it as build image on my project?

My colleague @keiko has followed up on your pull request. However I believe in your case, the core issue is the bug in node-libpq and I would suggest reaching out to this library as well.

1 Like