Continues deployment of functions with postgresql

Hi, I’m trying to deploy functions with continues deployment. I’m using node.js and postgresql as db. When I try to deploy from my local system using netlify-cli it deployed successfully but when I try to build directly from git it throws following errors:

My site url is https://grizz2.netlify.app/
I would really appreciate any help, thanks!

Hi @AsmaKhan

Given you have a node-gyp related error, I suggest the version of node on your local machine is lower (possibly v14.x.x) than the build system (v16.x.x). You can try downgrading node using the NODE_VERSION environment variable.

Also bear in mind you cannot run a node server or postgresql db on netlify (if that’s what you are expecting to do.)

Thanks for your reply. Yes my local node version is 12.22.1 and I’m using lambda-functions to run node backend with postgresql db and it is working every time I deploy changes using netlify-cli and always failed when try with git continues deployment. I understand from local system it uses dependencies installed on my system but gives error when netlify try to install them. I need a solution to overcome this node-gyp issue. I’ve tried downgrading the version as my local

NODE_VERSION
12.22.1

and tried to build again but didn’t work and gives following error.

It’s very difficult to diagnose issues from deploy screenshots. Can you post a link to the log instead.

Can you share your git repository?

12:34:01 PM: Installing NPM modules using NPM version 6.14.12
12:34:12 PM: npm WARN deprecated querystring@0.2.0: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
12:34:12 PM: npm WARN deprecated chokidar@2.1.8: Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 15x less dependencies.
12:34:12 PM: npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
12:34:12 PM: npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
12:34:13 PM: npm WARN deprecated fsevents@1.2.13: fsevents 1 will break on node v14+ and could be using insecure binaries. Upgrade to fsevents 2.
12:34:27 PM: > libpq@1.8.9 install /opt/build/repo/node_modules/libpq
12:34:27 PM: > node-gyp rebuild
12:34:29 PM: find: ‘/usr/pg*’: No such file or directory
12:34:29 PM: 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
12:34:29 PM: gyp ERR! configure error
12:34:29 PM: gyp ERR! stack Error: `gyp` failed with exit code: 1
12:34:29 PM: gyp ERR! stack     at ChildProcess.onCpExit (/opt/buildhome/.nvm/versions/node/v12.22.1/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:351:16)
12:34:29 PM: gyp ERR! stack     at ChildProcess.emit (events.js:314:20)
12:34:29 PM: gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:276:12)
12:34:29 PM: gyp ERR! System Linux 4.19.167+
12:34:29 PM: gyp ERR! command "/opt/buildhome/.nvm/versions/node/v12.22.1/bin/node" "/opt/buildhome/.nvm/versions/node/v12.22.1/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
12:34:29 PM: gyp ERR! cwd /opt/build/repo/node_modules/libpq
12:34:29 PM: gyp ERR! node -v v12.22.1
12:34:29 PM: gyp ERR! node-gyp -v v5.1.0
12:34:29 PM: gyp ERR! not ok
12:34:30 PM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@~2.3.2 (node_modules/chokidar/node_modules/fsevents):
12:34:30 PM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.3.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
12:34:30 PM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.2.7 (node_modules/watchpack-chokidar2/node_modules/chokidar/node_modules/fsevents):
12:34:30 PM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
12:34:30 PM: npm WARN grizz@1.0.0 No description
12:34:30 PM: npm ERR! code ELIFECYCLE
12:34:30 PM: npm ERR! errno 1
12:34:30 PM: npm ERR! libpq@1.8.9 install: `node-gyp rebuild`
12:34:30 PM: npm ERR! Exit status 1
12:34:30 PM: npm ERR!
12:34:30 PM: npm ERR! Failed at the libpq@1.8.9 install script.
12:34:30 PM: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
12:34:30 PM: npm ERR! A complete log of this run can be found in:
12:34:30 PM: npm ERR!     /opt/buildhome/.npm/_logs/2021-09-27T07_34_30_331Z-debug.log
12:34:30 PM: Error during NPM install
12:34:30 PM: Build was terminated: Build script returned non-zero exit code: 1
12:34:30 PM: Creating deploy upload records
12:34:30 PM: Failing build: Failed to build site
12:34:30 PM: Failed during stage 'building site': Build script returned non-zero exit code: 1
12:34:30 PM: Finished processing build request in 40.418348316s

Hi @AsmaKhan

What happens when you use 14.17.5 as the version and remove any package-lock.json file that you might have in your repo?

No I’ve removed the package-lock.json file from my repo. It gives node-gyp error when I try to deploy from repository. Please check the above reply for full error log.

Can you share your git repository?

sorry it is private repository and I do not have permissions to share, but I can provide information you need. i.e package.json

If you can post the contents of the package.json that might help

package.json

{
  "name": "grizz",
  "version": "1.0.0",
  "description": "",
  "main": "server.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "netlify-lambda serve functions",
    "build": "netlify-lambda build functions"
  },
  "repository": {
    "type": "git",
    "url": ""
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "bugs": {
    "url": ""
  },
  "homepage": "",
  "dependencies": {
    "body-parser": "^1.19.0",
    "cors": "^2.8.5",
    "dotenv": "^10.0.0",
    "encoding": "^0.1.13",
    "express": "^4.17.1",
    "firebase": "^8.7.1",
    "firebase-admin": "^9.10.0",
    "fs": "0.0.1-security",
    "handlebars": "^4.7.7",
    "jquery": "^3.6.0",
    "netlify-lambda": "^2.0.14",
    "ng": "0.0.0",
    "nodemailer": "^6.6.3",
    "path": "^0.12.7",
    "pg": "^8.7.1",
    "pg-native": "^3.0.0",
    "serverless-http": "^2.7.0"
  },
  "devDependencies": {
    "nodemon": "^2.0.12"
  }
}

Are you deploying a site along with the functions, or just trying to deploy the functions?

just trying to deploy the functions

The error boils down to the fact you have a dependency (it appears libpq, likely stemming from pg-native) that isn’t compatible with the current version of node on the build image. node-gyp errors are often found with node-sass when the package version is not compatible with the node version, and downgrading node using NODE_VERSION environment variable will fix this in most cases. Either that or upgrading the version of node-sass being used. (I know you aren’t using node-sass, but I use it as an example because the error is the same.)

Please also note the Self-Service Subscription Agreement which states:

… all functions hosted by Netlify are called primarily by a website hosted on our Services.

I’m hosting website on netlify but it is on other instance and continues deploy is working fine for that, issue is for backend instance. What NODE_VERSION is compatible for that? Please suggest.

I can offer no suggestions as I have no way of testing your code. If you are able to build locally specifying this version in the NODE_VERSION environment variable (as previously mentioned) will work (eg v12.22.1.)

yes I’ve already tried that v12.22.1 but it didn’t work

Given it is the lambda functions that are the issue AWS_LAMBDA_JS_RUNTIME is probably a more appropriate variable (instead of NODE_VERSION which is for the build environment), but AWS uses node.js 12 by default anyway as you are using.

Without a repository to test, it is virtually impossible to provide a concrete solution.

Hy @coelmay I’ve created a public repository GitHub - muzammalrahim/grizz-env with same development environment and on continues deployment getting same error please check here the error log Netlify App

In the log you shared @AsmaKhan I see

npm WARN deprecated chokidar@2.1.8: Chokidar 2 will break on node v14+.
Upgrade to chokidar 3 with 15x less dependencies.

Given the version of node

Now using node v16.13.0 (npm v8.1.0)

Chokidar is likely breaking. So you would need to either downgrade the node version used using NODE_VERSION environment variable as previously explained to a compatible version (likely v12 if Chokidar break on v14+) or update the packages you are using to the latest versions so they are compatible with node v16.