I have a Nuxt app backed by Supabase deployed on Cloudflare. It works fine.
Now I am trying to switch to Kysely for better control over database migrations. The Postgres dialect is backed by a Postgres module, either pg or postgres work locally.
When I deploy the changes to Cloudflare, I get an error when the build is prerendering. For postgres, the error is:
[error] [nitro] Error: Cannot resolve “cloudflare:sockets” from “/opt/buildhome/repo/node_modules/postgres/cf/polyfills.js” and externals are not allowed!
Something similar happens with pg, although it complains about pg-native instead. (I don’t have the error handy, since I tried that first.)
In the latter case, the “solution” I found is to exclude pg-native from the build. I tried this:
vite: {
build: {
rollupOptions: {
external: ['pg-native'],
},
},
},
but that didn’t change anything.
Am I out of luck with this combination: Nuxt (Nitro), Postgres, Cloudflare? Or does anyone know the correct way to exclude externals in a Vite build?
Zanzibar Hero is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.