-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Doesn't work with next.js Edge runtime #3206
Comments
Yeah it would probably...how does one reproduce this issue locally? If running in node then |
Set up a basic And then assume to use CloudFlare Pages requires a next.js app to specify that all backend endpoints will be using the edge runtime. There's a further complication that |
I am trying to use Prisma, PrismaPg and Pg.
Call Stack
https://vercel.com/docs/functions/runtimes/edge-runtime#unsupported-apis I know it's not really an issue related to Pg but I wanted to inform here anyway. |
I am using Next.js and Drizzle, and get the same: |
This patch fixes for me. Specifically: prevents the error
diff --git a/node_modules/pg/lib/crypto/utils-webcrypto.js b/node_modules/pg/lib/crypto/utils-webcrypto.js
index 0433f01..588066e 100644
--- a/node_modules/pg/lib/crypto/utils-webcrypto.js
+++ b/node_modules/pg/lib/crypto/utils-webcrypto.js
@@ -13,7 +13,10 @@ module.exports = {
* The Web Crypto API - grabbed from the Node.js library or the global
* @type Crypto
*/
-const webCrypto = nodeCrypto.webcrypto || globalThis.crypto
+
+// PATCH: Don't break under Next.js Edge runtime production build
+const webCrypto = ("webcrypto" in nodeCrypto ? nodeCrypto.webcrypto : undefined) ?? globalThis.crypto
+
/**
* The SubtleCrypto API for low level crypto operations.
* @type SubtleCrypto (I opted to use runtime-agnostic Feature Detection for |
Quick note from @prisma that this affects some of our users and is being reported to us: prisma/prisma#24430 (This issue has a reproduction, but that includes Prisma, Next.js and next-auth - that is probably a bit more than what you are asking for @brianc. I am pretty sure just trying to use We would love to see this fixed and released, so that Prisma users wanting to use |
k i'll get this looked at today if I have time! |
@janpio @andyjy @etodanik would one of y'all be able to provide me w/ more concrete steps to follow to set up a local reproduction? I did So i tested it at http://localhost:3000/api/hello and it worked. great. then I went into the route file and added export const runtime = 'edge' and now its erroring when I hit the route: So I'm doing something wrong, but not sure what. This is the full contents of my // Next.js API route support: https://nextjs.org/docs/api-routes/introduction
import type { NextApiRequest, NextApiResponse } from "next";
type Data = {
name: string;
};
export const runtime = 'edge'
export default function handler(
req: NextApiRequest,
res: NextApiResponse<Data>,
) {
res.status(200).json({ name: "John Doe" });
} |
@brianc here you go - reproduction for pages router: |
amazing, ty |
@andyjy when i applied your patch to the crypto file I now get this:
|
Update: 🤦♂️ sorry, I realised that while the patch I shared above indeed prevents the Next.js local edge runtime compilation error, I'm not actually executing the (I remembered I'm actually serving my API routes that use Sorry for the incorrect/misleading post previously! Thinking ahead to whether/how it's possible to get things actually working under the Next.js Edge runtime locally - it would probably(?) require breaking out of Next.js' local Edge Runtime "sandbox" to access If I get an actually-working prototype then I'll share back. |
Tiny PR to @andyjy's repro to show the same problem with a Next.js middleware, the common case where Prisma users run into this: andyjy/mre-pg-nextjs-edge#1
Semi informed comment from the sidelines: Afaik the Cloudflare Workers support for |
absolutely no problem! I'll continue to noodle on this....might take a bit of time to do a similar retrofit that the CF stuff did. I'm also about to go out of town for a bit so...hang tight - i'll get there eventually! |
I'm writing an app on
next.js
which I plan to deploy to CloudFlare Pages + Workers. I know there's CloudFlare support, but when running the local development server of next.js, I get the following errors:Would it make sense to generalize CloudFlare Workers detection into a broader Edge detection that also includes node edge runtime?
The text was updated successfully, but these errors were encountered: