sveltekit and node errors on build

Trying to use Sveltekit, with Supabase and Drizzle ORM preferably. - I've put nodejs_compat in the compatibility flags in both preview and production - Node version is 18 (set via environment variable) - I'm using build engine 1 - Using Sveltekit. - my postgres client instantiation is in $lib/server/ which I'm told makes it definitely server only - Using the cloudflare sveltekit adapter.
node_modules/postgres/cf/polyfills.js:1:29: ERROR: Could not resolve "node:events"
node_modules/postgres/cf/polyfills.js:2:23: ERROR: Could not resolve "node:buffer"
node_modules/postgres/cf/polyfills.js:1:29: ERROR: Could not resolve "node:events"
node_modules/postgres/cf/polyfills.js:2:23: ERROR: Could not resolve "node:buffer"
Cant seem to find anything online why it'd be throwing this.
3 Replies
boggin
boggin7mo ago
Also says The package "node:buffer" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error. but I have no clue where I would put this platform:'node' I've had no problems with builds until I added postgres Actually, so I'm using Drizzle ORM and their instructions for Cloudflare Workers say to use:
import { Pool } from "pg";
import { drizzle } from "drizzle-orm/node-postgres";
import { Pool } from "pg";
import { drizzle } from "drizzle-orm/node-postgres";
instead. I get these errors with pg ...
[ERROR] Could not resolve "events"
[ERROR] Could not resolve "stream"
[ERROR] Could not resolve "events"
[ERROR] Could not resolve "stream"
kian
kian7mo ago
node-postgres requires polyfills on Workers, usually provided by the node_compat Wrangler flags. The reason that you're getting errors with node: modules, despite having nodejs_compat enabled, is probably because the Svelte adapter doesn't have node: marked as external in their esbuild config (which Wrangler does). node_compat isn't available on Pages, meaning node-postgres isn't really an option unless you can provide the polyfills into the build process yourself.
boggin
boggin7mo ago
Thank you. Thats quite frustrating. Digging through github issues trying to find options