Cloudflare DevelopersCD
Cloudflare Developers3y ago
12 replies
deanmauro

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"
Was this page helpful?