node-postgres: node_modules/pg/lib/native/client.js:4:21: ERROR: Could not resolve "pg-native"
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
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 2
- Comments: 15 (2 by maintainers)
I’m using Vite and this worked for me:
We’re also running into this issue, we’ve imported
pgasand we’re bundling through esbuild:
esbuild ./src/ingest.ts --bundle --platform=node --outdir=distEDIT: We externalized the
pg-nativerequirement(--external:pg-nativefor esbuild)nuxt.config.ts -> nitro
For Nuxt / Nitro this did the trick:
BUT next error I get is:
So I also added
'cloudflare:sockets'to externals, too.I’m also getting this error, not that we do not specify that native or js will be used. we only import ‘pg’.
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’.