You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
UnhandledSchemeError: cloudflare when Using postgres with Cloudflare Workers and Next.js Edge Runtime #930
I'm encountering an issue while trying to deploy my Next.js API routes using the postgres package with Drizzle ORM on Cloudflare Workers. Everything works fine locally, but when I set export const runtime = "edge"; for the edge runtime in Next.js, I get the following error during compilation:
⨯ cloudflare:sockets
Module build failed: UnhandledSchemeError: Reading from "cloudflare:sockets" is not handled by plugins (Unhandled scheme).
Webpack supports "data:" and "file:" URIs by default.
You may need an additional plugin to handle "cloudflare:" URIs.
Import trace for requested module:
cloudflare:sockets
./node_modules/.pnpm/[email protected]/node_modules/postgres/cf/polyfills.js
./node_modules/.pnpm/[email protected]/node_modules/postgres/cf/src/index.js
./src/db/index.ts
./src/app/api/[[...route]]/routes/register/index.ts
./src/app/api/[[...route]]/routes/index.ts
./src/app/api/[[...route]]/route.ts
The error seems to originate from the postgres package when trying to use it with the edge runtime on Cloudflare Workers. It looks like Webpack doesn't know how to handle the cloudflare: scheme used in postgres/cf/polyfills.js.
Questions:
Is this a known issue with the postgres package when used in Cloudflare Workers with the edge runtime?
Are there any recommended workarounds or configurations that could resolve this issue?
Any guidance or suggestions would be greatly appreciated!
Thanks!
Reacted by Adrian Środoń, stungkit, Erez Drutin, Samuel Goldenbaum, Chris Baume, Luis Miguel Serrano, Niocas, Dmitry and D V Ramana
To avoid this issue, we recently switched postgres to @neondatabase/serverless. @neondatabase/serverless works well with the edge runtime and Next.js API.
But if I execute any script with the DB in a separate file, it gives some issues.
Activity
archodev commentedon Aug 17, 2024
Same issue, did you manage to fix this?
jacksonkasi1 commentedon Aug 18, 2024
Hi @archodev.
To avoid this issue, we recently switched
postgresto@neondatabase/serverless.@neondatabase/serverlessworks well with the edge runtime and Next.js API.But if I execute any script with the DB in a separate file, it gives some issues.
You can check out this repo, it's simple code: https://github.com/jacksonkasi1/drizzle-form
Also, you can reproduce the issue. I have commented code, check out:
src/db/index.tsv4