2

Has anyone successfully deployed a SvelteKit app using npm pg to Netlify/Vercel/Cloudflare? My local dev implementation works just fine with how I have it set up ( db.ts file with a query function in lib/server, and then using endpoint actions and the load function in +page.server.ts files)

My build errors are as follows: node_modules/pg-connection-string/index.js:3:18: ERROR: Could not resolve "url" node_modules/pg-connection-string/index.js:4:17: ERROR: Could not resolve "fs" node_modules/pg-pool/index.js:2:29: ERROR: Could not resolve "events" node_modules/pg-protocol/dist/parser.js:9:41: ERROR: Could not resolve "assert" node_modules/pg/lib/client.js:3:27: ERROR: Could not resolve "events"

And many of the above display a previous log message with something along the lines of:

✘ [ERROR] Could not resolve "buffer"

node_modules/safe-buffer/index.js:3:21:
  3 │ var buffer = require('buffer')
    ╵                      ~~~~~~~~

The package "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.

I've been trying to get it to just build and it seems like it isn't able to use the pg package because it isn't a true node server environment. For each adapter it attempts to build with (except the node adapter) it refuses to build anything to do with the pg npm package. I could be wrong about the why, but my question about the how remains.

My hope is to avoid something like Prisma (which hasn't been working for me either) and I am trying to do this as "intended" meaning that I want to use SvelteKit as both the front end and the true backend. So an additional express server or the like is not the solution I'm looking for.

EDIT: I have also successfully deployed the app to Azure using the node adapter, but pg AND Postgres.js both do not work.

ajh
  • 21
  • 2
  • Also of note in regards to this post I found: https://stackoverflow.com/questions/57161839/module-not-found-error-cant-resolve-fs-in There is a similar issue going on (different framework, sure but similar errors) and in this case, their solve *kinda* works in that it builds, but nothing actually gets served to the page when its on Cloudflare/Vercel/Netlify. It works locally, but again not on those hosting environments. – ajh Nov 04 '22 at 19:10

0 Answers0