Next.js Discord

Discord Forum

Enforcing edge runtime in local development environment

Unanswered
Northeast Congo Lion posted this in #help-forum
Open in Discord
Northeast Congo LionOP
I've run into two major issues with unsupported APIs so far targeting edge runtime. I'm using Next.js 13 with the app router to build some API endpoint to use with Inngest step functions. Everything works splendidly on my local environment, but when I deployed to Vercel I started getting edge-related failures. I would like to be able to know what these will be in my local development.

In my route.ts handler file I specify export const runtime = 'edge';

Specifically, locally (with next dev) I was allowed to:

* use Ajv which creates functions dynamically
* use the AsyncLocalStorage.enterWith() API

The latter one was really hard to figure out because this page https://nextjs.org/docs/app/api-reference/edge indicates AsyncLocalStorage is supported, but this page https://vercel.com/docs/functions/edge-functions/edge-runtime says it only supports a subset of that interface which does not include enterWith().

How can I make the local dev be as strict as the Vercel edge runtime so I can catch these errors before I deploy and before I get so far into my code it becomes hard to unwind?

17 Replies

this would work
im not sure i have not tried i
or use V8 isolates runtime directly
it’sCloudflare Worker so you might want to play around with CF Worker if you like
Northeast Congo LionOP
Using vercel dev also results in the same ability to call those APIs. It seems to just do some stuff then call next dev for you. I saw that edge runtime getting started page at vercel, and it looks like Next.js already pulls that module in as a dependency so I must assume it is what is being used. I cannot see how one would explicitly call it as part of my running my dev server anyway.
Actually Vercel Edge Runtime is Cloudflare Worker, V8 Isolates. so you could play around with CF directly. Here is local dev env.
https://blog.cloudflare.com/miniflare/
or just use CF instead of Vercel if u don't need AWS Lambda.
Northeast Congo LionOP
Thanks for the link. That seems quite a bit of work to switch out from Vercel to deploy to Cloudflare, and was something I was going to investigate anyway. Still it seems to me that the vercel local development tool set should mimic their real environment better.
Vercel uses Cloudflare Worker under the hood so technically it’s the same
or ask at the Cloudflare Discord community
Northeast Congo LionOP
In the intro section of the Edge Runtime documentation linked above, it says "When developing and testing locally, the Edge Runtime will polyfill Web APIs and ensure compatibility with the Node.js layer." What on earth is the benefit to this? This is the exact opposite behavior it should be doing.
Northeast Congo LionOP
I think looking to wrangler with miniflare is the way to go.
meaning V8 Isolates on top of Node,js
enterWith is experimental btw