Use `pg` in Pages Function?
I want to access a PostgreSQL database in a function that will be deployed via Cloudflare Pages. Workers supports using
pg
, the common Node PostgreSQL database.
But I can not make it work with the Functions in Pages. I get errors like this on pnpm wrangler pages dev .
-:
If I understand the error message correctly, I am supposed to do pnpm wrangler pages dev . --compatibility-flag="nodejs_compat"
- but that returns exactly the same error.
(I know that in Workers I actually need to use
node_compat
(which sounds similar, but it something very different) - but that does not seem to exist for Pages)2 Replies
pg
does indeed require node_compat
, not nodejs_compat
.
You could use Postgres.js in Pages with nodejs_compat
.Unfortunately not really an option as I am testing a library (Prisma) here that enables usage of
pg
, because that is what the library users are asking for.
I found https://github.com/cloudflare/workers-sdk/issues/1074 and https://github.com/cloudflare/workers-sdk/pull/2541, but seems there was no conclusion to these.