unable to deploy sveltekit when using postgres
I've been trying to deploy sveltekit using postgres, but am unable to get it to work with
compatibility_flags = [ "nodejs_compat" ]
or node_compat = true
... I've made minimal repos showing it working with the default esbuild process wrangler does, while failing with sveltekid (which uses vite).
Is anyone doing this something similar successfully? Any hints on how to tweak my vite.config.js
to get it to work?
Failing (sveltekit): https://terrible.software/terribleplan/svelte-kit-pg-cloudflare
Working (no framework at all): https://terrible.software/terribleplan/raw-pg-cloudflare
If you want to deploy the examples yourself make sure you update the wrangler.toml
with a valid hyperdrive id.
The errors I am getting from vite are of this variety (depending on how exactly I tweak my wrangler config to use compatibility_flags = [ "nodejs_compat" ]
or node_compat = true
):
Terrible Software
svelte-kit-pg-cloudflare
Terrible Software
raw-pg-cloudflare
8 Replies
It is fairly confusing right now sadly, but Pages only supports wrangler.toml in dev. In prod, it ignores it entirely. Pages does not support hyperdrive or node_compat right now, only the nodejs compat flag. And pg only supports node_compat, not nodejs_compat
node_compat -> polyfills in node stuff like path, only supported in Workers (or in pages if you custom build everything)
nodejs_compat -> compat flag which adds in node:path and some popular node stuff in from the runtime, does not increase bundle size
You could use a Worker and bind your Pages to it via a Service Binding
As far as I can tell the issue isn't with the binding, and FWIW I am using workers:
whoops somehow I had it in my head you were trying to use Pages, most people using Sveltekit do.
pg only supports node_compat = true. What error do you get with that?
Here are the full logs for
node_compat = true
As an interesting note
compatibility_flags = [ "nodejs_compat" ]
leads to fewer errors.
All of the issues seem to be in the build stage, before the actual deploy to CF regardless.node_compat just
This is currently powered by @esbuild-plugins/node-globals-polyfill which in itself is powered by rollup-plugin-node-polyfillsyou're not using wrangler's build process/you're using vite instead could try something like this: https://www.npmjs.com/package/vite-plugin-node-polyfills, not sure though, nothing I've tried before
Yeah, vite is what svelte uses for its builds. Nothing changed when adding those polyfills, so it may be something with how the svelte plugin works. It isn't entirely clear what is producing those error messages, or why it is even when the node compat flag is there which should let me use (at least some of) the packages it is complaining about...
it's vite. Normal wrangler deploy uses esbuild which uses that plugin when node_compat is enabled. You're not building through esbuild/normal wrangler though
All that option really does is tell esbuild to include node-globals-polyfills when it bundles your code