#Is it possible to use postgres with astro SSR running on cloudflare adapter?

4 messages · Page 1 of 1 (latest)

primal lynx
#

I'm just getting started with astro (and I'm loving it!). I've created an app that pulls content from our postgres db and works in dev. If I use a node adapter I'm able to run a build succesfully but if I try to use the cloudflare adapter, I get the following error when I run the build:

[commonjs--resolver] [plugin vite:resolve] Cannot bundle Node.js built-in "node:events" imported from "node_modules/postgres/cf/polyfills.js". Consider disabling ssr.noExternal or remove the built-in dependency.

My astro.config.mjs looks like this:

import { defineConfig } from 'astro/config';

import cloudflare from '<@&1055234544183287879>/cloudflare';

// https://astro.build/config
export default defineConfig({
output: 'server',
adapter: cloudflare(),
});

alpine thistle
primal lynx
#

Thanks @alpine thistle ! I've managed to get it to build by adjusting my config as follows:

export default defineConfig({
output: 'server',
adapter: cloudflare(),
vite: {
ssr: {
external: ['node:events', 'node:buffer', 'cloudflare:sockets', 'node:stream'],
},
build: {
rollupOptions: {
external: ['cloudflare:sockets'],
},
},
},
});

primal lynx
#

My build works when the output is set to 'server' but if I try to switch output to 'hybrid' it fails with the following error:
/index.htmlOnly URLs with a scheme in: file, data, and node are supported by the default ESM loader. Received protocol 'cloudflare:'