porsager / postgres

Postgres.js - The Fastest full featured PostgreSQL client for Node.js, Deno, Bun and CloudFlare
The Unlicense
7.26k stars 262 forks source link

Error: Cannot resolve "cloudflare:sockets" from "...\node_modules\.pnpm\postgres@3.4.0\node_modules\postgres\cf\polyfills.js" and externals are not allowed! #727

Closed dev-cetus closed 9 months ago

dev-cetus commented 9 months ago

hi, I'm using Nuxt 3 v3.8, and I'm trying to deploy to cloudflare with the cloudflare preset. But I get the following error: image I've seen that you've already created a fix for this error, but I'm using version 3.4.0 of postgres and the error is still there...

My wrangler.toml file contains the line:

node_compat = true
porsager commented 9 months ago

Any luck with the latest ? (v3.4.3)

dev-cetus commented 9 months ago

Doesn't work, same error... You can check de code.
build it with

$env:NITRO_PRESET='cloudflare'; $env:NUXT_JWT_SECRET='djisiu'; $env:DATABASE_URL='postgres://postgres:postgres@localhost:5432/postgres'; pnpm run build

(database is not required for build)

porsager commented 9 months ago

Sorry, but I'm not going to debug why some other build tool doesn't know how to handle this. Create an issue in their repo.

bllchmbrs commented 8 months ago

@dev-cetus , did you figure out how to get this working?

I am trying to run Cloudflare Pages Functions with Nuxt 3.8.2. and this library(postgres(3.4.3) and it fails with the same approximate error during build.

[error] Cannot resolve "cloudflare:sockets" from "/opt/buildhome/repo/node_modules/postgres/cf/polyfills.js" and externals are not allowed!

Pages functions don't support

node_compat = true

or toml files at all. Now you can set nodejs_compat but that doesn't work out of the box.

This issue seems related to:

It comes up a lot in this repository.

Now this appears to be something related to bundling as @porsager mentions in the various threads (be it webpack, or vite, or whatnot). I just don't know enough about the JS tools to actually debugging - I'm just a user who wants to access a postgres database.

This comment seems like the most thorough on the subject and I'm just hoping that either (a) someone can help resolve this issue, (b) to leave breadcrumbs for others or (c) at least rubber 🦆 my way out of this... Any help appreciated.

MickL commented 6 months ago

Same issue Vercel Edge Functions. This issue is not regarding Cloudflare, but regarding serverless edge workers environments. This project does not work on serverless edge workers. @porsager do you mind reopening this issue?

I wonder why postgres adds this polyfills anyway. If they would be removed and rather be optional the problem might be solved.

alexcroox commented 4 months ago

Did anyone find a workaround in the end? Keen to use Postgres on CF but this polyfill error on build is blocking progress. Thanks!

minemos commented 4 months ago

Any updates?

Dxuian commented 3 months ago

still isnt fixed

porsager commented 3 months ago

Try installing latest from github npm install porsager/postgres

I'll make a release soon if that works fine 😉

chenrui333 commented 2 months ago

I just tried npm install porsager/postgres, got this error instead

 ⨯ ./node_modules/.pnpm/postgres@https+++codeload.github.com+porsager+postgres+tar.gz+f58cd4f3affd3e8ce8f53e42799672d86cd2c70b/node_modules/postgres/src/connection.js:1:1
Module not found: Can't resolve 'net'
porsager commented 2 months ago

@chenrui333 what platform are you trying to use it on?

chenrui333 commented 2 months ago

I am using vercel edge runtime for the backend. Switch off resolved the issue if that helps.

porsager commented 2 months ago

Yeah. You can't make tcp connections from vercel edge, so Postgres.js won't work there. Neon works because the proxy through websockets.