Immutable solution version
Websocket error on Vercel Serverless Function
Complete solution
How to fix 'Websocket error on Vercel Serverless Function' in Neon, straight from the verified resolution in gh:neondatabase/serverless#15. Root cause plus what to change.
What was reported
Issue neondatabase/serverless#15 (closed, 12 comments):
I'm getting the following error when using this on vercel
Unhandled Promise Rejection {"errorType":"Runtime.UnhandledPromiseRejection","errorMessage":"Error: All attempts to open a WebSocket to connect to the database failed. If using Node, please install the `ws` package (or simply use the `pg` package instead).","reason":{"errorType":"Error","errorMessage":"All attempts to open a WebSocket to connect to the database failed. If using Node, please install the `ws` package (or simply use the `pg` package instead).","stack":["Error: All attempts to open a WebSocket to connect to the
## The verified resolution
[jawj (maintainer)]: On Vercel's non-Edge serverless functions the WebSocket transport may fail to open; in that environment just use ordinary node-postgres (`pg`) instead of the serverless driver. On Edge functions the driver works (no need to set webSocketConstructor there). Local `npx vercel dev` was also updated to support both. No driver bug - environment limitation.Evidence
Asked in gh:neondatabase/serverless#15 (https://github.com/neondatabase/serverless/issues/15): Websocket error on Vercel Serverless Function. The issue report: Issue neondatabase/serverless#15 (closed, 12 comments):
I'm getting the following error when using this on vercel
Unhandled Promise Rejection {"errorType":"Runtime.UnhandledPromiseRejection","errorMessage":"Error: All attempts to open a WebSocket to connect to the database failed. If using Node, please install the `ws` package (or simply use the `pg` package instead).","reason":{"errorType":"Error","errorMessage":"All attempts to open a WebSocket to connect to the database failed. If using Node, please install the `ws` package (or simply use the `pg` package instead).","stack":["Error: All attempts to open a WebSocket to connect to the The verified answer: [jawj (maintainer)]: On Vercel's non-Edge serverless functions the WebSocket transport may fail to open; in that environment just use ordinary node-postgres (`pg`) instead of the serverless driver. On Edge functions the driver works (no need to set webSocketConstructor there). Local `npx vercel dev` was also updated to support both. No driver bug - environment limitation.By @issueatlas · Version 1 · Exact version
Reported outcomes
No reported outcomes for this version yet.
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl___TVCCNjybydk6dyYYK6Yg" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Websocket error on Vercel Serverless Function <span>— Vectle</span></a>