Continues deployment of functions with postgresql

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.

Yes I’ve tried to downgrade the version to 12 and even 10. It didn’t work and gives the same warning. But the actual issue is here

3:26:26 PM: npm ERR! find: ‘/usr/pg*’: No such file or directory
3:26:26 PM: npm ERR! 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

Hi @AsmaKhan,

I can see you’ve found this thread already:

which was already left without a solution. I believe this might not work.

Is it issue at netlify end, as it works fine when I try to deploy with netlify-cli from my local system.

As I’ve said there and saying here:

Netlify is not equal to your local system, there are lot of differences between the two environments and one should not compare those. Please read my above post for details.

1 Like

First of all Thanks for your reply. Yes I understand that but just wanted to know if Netlify team is trying to solve this issue? Any workaround? As you know because of this issue we are not able to avail “Continues Deployment” feature.

I had shared this link in the above thread: Unable to publish function using postgres - #2 by ehmicky

Did you try that? Since the person in that previous thread didn’t post an update, did you have any luck trying it out?

I’m not quite sure where I need to run these installations.

RUN apk --no-cache add make python gcc postgresql-dev g++
RUN yarn install

Hi @AsmaKhan,

Please follow the links in those threads which will explain that running that command is not possible. Instead this is a linked issue which would be more useful:

Also, as mentioned in that thread, it could be a bug in the underlying library.

Hello, happy to stumble upon this topic, took me dozen of failed builds to realize there’s a problem with installing node-postgres driver properly.

I believe I’ve found a solution. Frankly, it isn’t a solution to the bug but rather an alternative.

porsager’s postgres driver - It’s a postgresql node driver with zero dependencies, therefore no libpq bugs.

I understand it may be a cumbersome to rewrite larger codebases to suit this driver’s api, in my case my app is really minimalistic so it wasn’t a problem.

I hope it helps.