Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

serverless-pg with Netlify #70

Open
arnaudjnn opened this issue Jun 9, 2022 · 6 comments
Open

serverless-pg with Netlify #70

arnaudjnn opened this issue Jun 9, 2022 · 6 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@arnaudjnn
Copy link

I'm using Netlify functions for serverless

When I tried serverless-pg I had the following error:

[ERROR] Could not resolve "pg-native"
    node_modules/pg/lib/native/client.js:4:21:
      4 │ var Native = require('pg-native')

So I installed pg-native, working well locally but then I have the following error with deploy: https://answers.netlify.com/t/unable-to-publish-function-using-postgres/12293

Do you have an install with Netlify? How can I fix the error with libpq?

@MatteoGioioso
Copy link
Owner

Any chance you have this variable set? NODE_PG_FORCE_NATIVE
https://github.com/brianc/node-postgres/blob/28ac2a17bce287cfa458153dcabe3ca06ca0e28f/packages/pg/lib/index.js#L28

I have never used Netlify myself, but I have found something: brianc/node-postgres#1894 (comment)

@arnaudjnn
Copy link
Author

@MatteoGioioso I tried to set NODE_PG_FORCE_NATIVE but this does not solve the error.

Is it possible to use postgres instead pg as detailed here?

https://answers.netlify.com/t/continues-deployment-of-functions-with-postgresql/44730/30

@MatteoGioioso
Copy link
Owner

MatteoGioioso commented Jun 10, 2022

@arnaudjnn I think you should unset it.

regarding to use another library, I think it should be possible:

it("should allow custom library usage", async function () {

however the API must be compatible

@arnaudjnn
Copy link
Author

Sorry no I haven't this variable NODE_PG_FORCE_NATIVE

How would you do to use another library like postgres ?

Would be awesome to get an example working with Netlify!

@MatteoGioioso
Copy link
Owner

MatteoGioioso commented Jun 10, 2022

You could try something like that

const yourDriver = require("custom-driver")

const client = new ServerlessClient({
  ...dbConfig,
  debug: true,
  library: yourDriver
});

although I see that the library you are suggesting use quite different API. I will test something and let you know.

PS: have you tried this? brianc/node-postgres#1894 (comment)

@AWare
Copy link

AWare commented Dec 20, 2022

It may be worth considering running the library through a bundler to make this problem go away.

I've spent most of today trying to get pg through parcel without any luck, and it would certainly make some sense for this library to deliberately excise pg-native for ease of bundling.

@MatteoGioioso MatteoGioioso added bug Something isn't working help wanted Extra attention is needed labels Feb 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants