postgres orm drizzle setup can not be bundled by rollup
I've used the cloudflare pages template for qwik ( https://developers.cloudflare.com/pages/framework-guides/deploy-a-qwik-site/ ). Then following the guide for integrating hyperdrive I added
postgres.js
and drizzle
. When trying to run the build
script I get the following error
This library is recommended by the cloudflare docs ( https://developers.cloudflare.com/hyperdrive/learning/connect-to-postgres/ ) so I'm confused why it is giving errors.
Anyone know how to fix this?7 Replies
I tried to override the build config with
which allows it to build, but that results in
when running
pages:deploy
I don't understand how in the cloudflare docs https://developers.cloudflare.com/workers/tutorials/postgres/ they just do import { Client } from "pg";
but don't explain how that handles the package's build-in node dependencies
I found an old blog post https://blog.cloudflare.com/workers-tcp-socket-api-connect-databases/ about the tcp socket api that mentions you need to enable node_compat
in the worker. but I can not create a wrangler.toml
for pages, how am I supposed to enable node_compat for a pages
app?
Well I tried adding nodejs_compat
to compatibility flags in the cloudflare console, but trying to deploy again results in the same error.I don't think you can for Pages, unfortunately.
node_compat
is different to nodejs_compat
It's a set of polyfills added by an esbuild pluginHow can cloudflare be promoting these features like HYPERDRIVE and have it only available for
workers
and not pages
. Is it really so different? All these resources to get started on pages with so many frameworks and in the end they are useless because you don't get feature parity with plain workers. It is extremely frustrating trying to work with cloudflare...
Thanks for your answer though, sorry for the rant.You can try add it into rollup yourself - https://github.com/ionic-team/rollup-plugin-node-polyfills/
GitHub
GitHub - ionic-team/rollup-plugin-node-polyfills
Contribute to ionic-team/rollup-plugin-node-polyfills development by creating an account on GitHub.
It's giving issues but I don't think it will work regardless, I think hyperdrive relies on the node_compat to use the tcp socket api
Hyperdrive itself doesn't, but the
pg
library does.
node_compat
is just @esbuild-plugins/node-globals-polyfill
, which is just rollup-plugin-node-polyfills
.
What errors do you get after adding that plugin into rollup?I'm getting
instead of it asking what project to deploy to, I re-made the project a few times to test the compat modes, it's stuck on the old project name for some reason even though I have not hardcoded that anywhere
does wrangler have any cache location?
ah i got passed that by removing
node_modules
and re-installing.
Okay it deployed successfully, giving an error because I have not configured the connection string environment variable yet... so let's try that
Well.. managed to get the hyperdrive config created, but no way to bind it to a pages
app, should have seen that coming by now