-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
node_modules/pg/lib/native/client.js:4:21: ERROR: Could not resolve "pg-native" #2800
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
Comments
You need to install
|
Hi brianc, It looks like it has something to do with the bundler (I'm using Remix.run). I'm trying to solve it on that end. Regarding the v8:
I can't share the scripts nor the repo since it's private... |
Hi @brianc Should I install
|
If you're using a bundler that's likely the problem. Native code doesn't bundle well. Just use the pure JS bindings - I use them currently in prod and they're very fast. |
We're also running into this issue, we've imported import { Client } from "pg"; and we're bundling through esbuild:
EDIT: We externalized the |
@brianc , I'm facing the same issue, and I'd like to test your solution:
But I don't know what you mean by "Just use the pure JS bindings". I'm not doing anything specific that would make me use the non-pure JS bindings. Can you please elaborate what you mean and how we can use the pure JS bindings? Thanks. |
I'm also getting this error, the problem is the code automatically tries to import pg-native which does not exist. We cannot use pg-native in serverless platforms. So maybe Client and NativeClient should be separate then webpack will not try to include 'pg-native'. |
Are you using an ORM package, like TypeORM? |
No, I'm using Cloudflare workers with TypeScript. When trying to run the code as I understand it bundles the code with webpack. And because libpq is not installed on my machine (also in the cloud) pg-native cannot be installed too. So I get this error. |
I meant, in what context to you use PG? I know for example that, when using TypeORM, you can - and you should IMHO - force the driver that you want to use and that it default to pg-native. |
@mrcndn You might also need to configure your bundler to ignore |
It would be great if libs stopped doing dynamic - and implicit - imports once and for all so that we don't have to guess their internals just to build an application. People that want to use pg-native should have to import the package explicitely and pass it as configuration to the library. |
I'm using Vite and this worked for me:
|
For Nuxt / Nitro this did the trick: rollupConfig: {
external: ['pg-native'],
}, BUT next error I get is:
So I also added |
nuxt.config.ts -> nitro nitro: {
rollupConfig: {
external: ['pg-native', 'cloudflare:sockets'],
},
}, |
Hi,
I'm receiving this error when I run my code
node_modules/pg/lib/native/client.js:4:21: ERROR: Could not resolve "pg-native"
Do I need to install pg-native? When I did the tests started crashing with FATAL ERROR, with something related to v8...
Is there any alternative here? I'm using pg Pool to make simple queries and typeorm as orm
The text was updated successfully, but these errors were encountered: