Using connect() API in Pages

Hi team. I have a Pages function that talks directly to a Postgres DB using the new connect() API (detailed here: https://developers.cloudflare.com/workers/databases/connect-to-postgres). The code works fine in a Worker and also when running Pages locally. But when trying to deploy to CF, I get node compatibility errors. I have the nodejs-compat flag set. What am I missing?
14:22:33.131 ✘ [ERROR] Could not resolve "stream"
14:22:33.131
14:22:33.131 ../node_modules/pgpass/node_modules/split2/index.js:19:30:
14:22:33.131 19 │ const { Transform } = require('stream')
14:22:33.132 ╵ ~~~~~~~~
14:22:33.132
14:22:33.132 The package "stream" wasn't found on the file system but is built into node.
14:22:33.132 Add the "nodejs_compat" compatibility flag to your Pages project to enable Node.js compatibility.
14:22:33.132
14:22:33.133
14:22:33.133 ✘ [ERROR] Build failed with 12 errors:
14:22:33.133
14:22:33.134 ../node_modules/pg-connection-string/index.js:72:77: ERROR: Could not resolve "fs"
14:22:33.134 ../node_modules/pg/lib/connection-parameters.js:3:18: ERROR: Could not resolve "dns"
14:22:33.134 ../node_modules/pg/lib/connection.js:3:18: ERROR: Could not resolve "net"
14:22:33.134 ../node_modules/pg/lib/crypto/utils-legacy.js:5:27: ERROR: Could not resolve "crypto"
14:22:33.134 ../node_modules/pg/lib/crypto/utils.js:10:27: ERROR: Could not resolve "crypto"
14:22:33.131 ✘ [ERROR] Could not resolve "stream"
14:22:33.131
14:22:33.131 ../node_modules/pgpass/node_modules/split2/index.js:19:30:
14:22:33.131 19 │ const { Transform } = require('stream')
14:22:33.132 ╵ ~~~~~~~~
14:22:33.132
14:22:33.132 The package "stream" wasn't found on the file system but is built into node.
14:22:33.132 Add the "nodejs_compat" compatibility flag to your Pages project to enable Node.js compatibility.
14:22:33.132
14:22:33.133
14:22:33.133 ✘ [ERROR] Build failed with 12 errors:
14:22:33.133
14:22:33.134 ../node_modules/pg-connection-string/index.js:72:77: ERROR: Could not resolve "fs"
14:22:33.134 ../node_modules/pg/lib/connection-parameters.js:3:18: ERROR: Could not resolve "dns"
14:22:33.134 ../node_modules/pg/lib/connection.js:3:18: ERROR: Could not resolve "net"
14:22:33.134 ../node_modules/pg/lib/crypto/utils-legacy.js:5:27: ERROR: Could not resolve "crypto"
14:22:33.134 ../node_modules/pg/lib/crypto/utils.js:10:27: ERROR: Could not resolve "crypto"
5 Replies
deanmauro
deanmauro13mo ago
Yes, I'm using the latest v8.11.0 It works locally with the deprecated --node-compat flag. I'm not having any luck setting the nodejs-compat compatibility-flag. It doesn't seem to have an effect. Is node compatibility supported in Pages functions?
Walshy
Walshy13mo ago
It requires the wrangler node compat flag not the compatibility date node compat flag (yes it's confusing notlikemeow ) Publish/UI doesn't have --node-compat
deanmauro
deanmauro13mo ago
If I'm understanding correctly, that means pg isn't supported in Pages yet since the --node-compat flag isn't available? It will only work in a worker?
Walshy
Walshy13mo ago
You could do the node pollyfills yourself but natively with wrangler, yes hopefully it'll just work soon with the native node compat
deanmauro
deanmauro13mo ago
Okay that's not necessarily so bad. I can either add polyfills for the pages functions or bind a worker. Do you have any guidance or docs on hand for adding polyfills in pages?