pg example not working
I followed the example from the Cloudflare documentation for connecting to Postgres using node-postgres / pq at the link: https://developers.cloudflare.com/hyperdrive/configuration/connect-to-postgres/#node-postgres–pg. However, I encountered the error “this.stream.once is not a function.”
According to this compatibility matrix (https://workers-nodejs-compat-matrix.pages.dev/), nodejs_compat_v2 should support the .once method on streams. Is there a related issue or a step I might have overlooked? My code is based on the documentation, and you can view it here: https://github.com/waigel/example-pg-cloudflare. Any suggestions or help would be appreciated!
Workers Node Compat Matrix
demo site
Cloudflare Docs
Connect to PostgreSQL | Hyperdrive
Hyperdrive supports PostgreSQL and PostgreSQL-compatible databases, popular drivers and Object Relational Mapper (ORM) libraries that use those drivers.
1 Reply
Hey @mike, I'll dig in here in a bit.
If you set
node_compat = true
in your wrangler.toml instead of compatability_flags = ["nodejs_compat_v2"]
do you know if it works?
It should work with V2 and node_compat = true
is meant to be replaced, but it'd be helpful for debugging to see if it works in this case.
Update on this one: It works now with pg
and nodejs_compat
if you're on the latest wrangler and the latest version of pg!
There was some feature detection in the package that we needed to push an upstream patch to fix and then a crypto-related bug in unenv we also patched that was surfaced too.
Thanks for the feedback on this one!