-
Notifications
You must be signed in to change notification settings - Fork 38
[BUG] postgres throws errors at runtime #548
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Could you attach a repro with a DB URL populated so that we can reproduce? (link to a GH repository) You can also give Hyperdrive a try |
@vicb I've created a private repo, so I don't publicly leak my db password. I've sent you the invite |
I ran into the same problem. (you can create a DB for free at Neon and reproduce this) Same code works fine in a normal Worker – just not when compiled with |
@mhart my current workaround is to use neon's serverless driver. But I don't believe that it's universal. It didn't work with supabase's postgres db. So the vendor- lock is not ideal. @vicb using hyperdrive on top of the postgres-js driver did not fix the issue. The invite is still pending, let me know if you're having any issues with accessing the reproduction repo. |
I suspect the issue is here: https://github.com/porsager/postgres/blob/089214e85c23c90cf142d47fb30bd03f42874984/package.json#L11 Basically this won't get included correctly under an OpenNext build because the esbuild platform is set to However, under a normal Worker build, |
We experienced the same issue. After investigating, I believe the reason @mhart mentioned is correct. |
"postgres": "^3.4.4", This happens occasionally. A page may be normal when opened first, but these errors will appear when opened again, and normal and abnormal situations appear alternately. I suspect it is related to the database? I use hyperdrive and my project is nextjs |
@Msekoo @mhart @MingkaiChen @ka-raa-ge Could you guys try with this PR ? #593 (comment) |
Describe the bug
Using the postgres-js driver to access a database works correctly on the first request, but fails with the following errors on every other subsequent request.
Steps to reproduce
npm create cloudflare@latest -- my-next-app --framework=next --platform=workers
npm install --save postgres
DATABASE_URL
defined to a valid pg database:app/page.tsx
with the following. Change the db query to match a test table in your databse.npm run preview
Expected behavior
The request should consistently resolve, fetching from the database and return the data.
An equivalent request on a bare-bones typsecript cloudflare worker project resolves the same request without issues.
@opennextjs/cloudflare version
~1.0.0-beta.0 || ^1.0.0
Wrangler version
^4.8.0
next info output
Operating System: Platform: linux Arch: x64 Version: #1 SMP Tue Nov 5 00:21:55 UTC 2024 Available memory (MB): 31983 Available CPU cores: 20 Binaries: Node: 22.14.0 npm: 10.9.2 Yarn: N/A pnpm: 10.8.0 Relevant Packages: next: 15.2.4 // Latest available version is detected (15.2.4). eslint-config-next: 15.2.4 react: 19.1.0 react-dom: 19.1.0 typescript: 5.8.3 Next.js Config: output: N/A
Additional context
No response
The text was updated successfully, but these errors were encountered: