Edge function crashing on production, works as expected in other environments

site: https://super-selkie-0ef4d9.netlify.app/
dev live: https://super-selkie-0ef4d9-1583f4.netlify.live/

Hey everyone,

I’m running into a strange issue with Edge Functions.

I have a couple of edge functions that do some thing with Stripe and save some things to a supabase db. I’ve been able to get these functions working locally, and on the dev --live environment, but for some reason when I deploy my site to production, the edge functions crash. There is nothing logged to the edge functions console either.

I’ve mostly narrowed it down to one import:

import Stripe from "https://esm.sh/stripe?no-check";

// edge function code

If I deploy an empty edge function without this Stripe sdk esm wrapped import, it works as expected. However, when I use this import (only in production, works fine in local and live dev), the function crashes without any additional logs.

You can see the behavior on the prod site vs dev live as they’re currently deployed.

I also noticed (but don’t know if it’s related), that the environment variables available in production seem to be different than what are available in dev live. For example, the URL var is available in dev live, but not in production.

I’m really puzzled by this, and it doesn’t seem like anyone else has run into this problem. Any ideas?

Thanks in advance!

Hey @tindleaj ,

Would it be possible to share the reproduction steps on the live site so that we may take a closer look?

Also, you mentioned that env vars are different in production versus dev live. I see you have env var defined in the UI > Site settings and was wondering if you have env vars defined elsewhere like in netlify.toml?

Whoops, yeah of course.
Reproduction:

  1. Click the ‘I would pay $5 for this’ button
  2. Wait for redirect to crash page ~10 sec

I don’t have any envs defined in netlify.toml, I do have some defined in a local .env

Thanks for the help Audrey!

The envs are the same in both the url and the local env file, same keys and values

REACT_APP_SUPABASE_URL, REACT_APP_SUPABASE_ANON_KEY, STRIPE_API_KEY

Error message: The deployment failed while serving the request.
Netlify internal ID: 01G63X67TEG5M1FFA6ARZJ46QW

hi there @tindleaj - we are still discussing this internally, and will have more information for you soon.

Sure, also I switched to a Next.js / netlify functions stack for now, just to get my MVP working, but I’m happy to redeploy the old edge-function version if it will help you troubleshoot

Hey @tindleaj,

Note that, everything that works in Netlify Functions, is not expected to work in Netlify Edge Functions (and vice-cersa). They’re using two different runtimes (Node vs Deno) so, you can expect stuff accordingly.

Not saying you did not know this, just wanted to make it clear if you didn’t and for other folks who might consider both as direct replacements of each other.

About the library not working, have you checked this:

It appears that Stripe doesn’t have any good ways (yet) to work on Deno. Did you try contacting them about it?

Hey @hrishikesh! Thanks for the follow-up.

Totally understand the difference between regular functions and edge, I’ve been having fun exploring Deno and edge computation and it’s super cool Netlify is adding it.

From that first ticket, it looks like some people have gotten it to work in some deno environments, and Stripe has deno examples like this one. It’s also puzzling because everything works locally, which as I understand is still a deno environment.

Hey there, @tindleaj :wave:

My apologies for the delay here! Can you outline your use case more specifically? Why did you choose to use Edge Functions for this vs. Netlify Functions? Additionally, can you share the exact error message you are seeing?

Understanding your use case as well as the specific error will help us understand your approach more clearly and offer appropriate next steps.

Thanks again!

I’m also running into this issue. netlify dev works fine locally, the deploy builds without error, but ALL my edge functions crash (not just the one utilising Stripe) with the following output:

This edge function has crashed

An unhandled error in the function code triggered the following message:

The deployment failed while serving the request.

Connection details

Netlify internal ID: 01G9J4P5YVXJ09H3AJQV5N3BSK

Currently nothing is output in the logs whatsoever, however a couple of days ago I was getting:

Identifier 'DenoStdInternalError' has already been declared

Note: I’ve tried the import as all 3 of the following variations:

import Stripe from "https://esm.sh/stripe?target=deno";
import Stripe from "https://esm.sh/stripe?no-check";
import Stripe from "https://esm.sh/stripe?no-check&target=deno";

Is there somewhere the Deno version is output? Without any logs or even a Deno version number, it’s hard to debug whether this is a Netlify, Deno or Stripe issue.

@hillary your question wasn’t directed at me but in terms of why I’m trying to use Edge Functions over Netlify Functions:

  1. I’ve already got a bunch of other edge functions in this project so makes a logical default starting point
  2. There’s code that needs sharing between the functions, given the different function signatures of functions and edge functions, this makes it harder to share code productively
  3. Control over URLs is necessary, Netlify Functions require the /.netlify/ URL prefix
  4. It’s desirable to keep latency a low as possible, iirc Netlify Functions are deployed solely in us-east-1, rather than being globally distributed?

Update: furthermore to #2 above, base64 encoding/decoding compatibility between Deno and Node.js is a true nightmare. Trying to sign data in Deno that needs verifying in Node and the browser is proving next to impossible.

Regarding your error, have you got some environment variables stored in the Netlify UI? Maybe in the “new experience” that the UI might have suggested? If yes, could you try switch to the old experience and see if the error persists? I’m seeing some log about this new experience and thus, wanted to make sure.


Not totally related, but I had a few clarifications to make:

That need not be necessarily true. The two features have a very different use cases. For example, if someone already has a bunch of Netlify Functions in their project, we won’t ask them to make use of another Netlify Function if they wish to do something like transform a HTTP request and manipulate the response and vice versa. Having one of a particular tool, doesn’t necessarily mean that you need to have the entire project in the same tool.

I can understand the problem with number 2 though.

Not necessarily. That’s what rewrites are for: Rewrites and proxies | Netlify Docs. You can see it in action on this project: GitHub - Hrishikesh-K/netlify-file-browser: Preview or download files from your Netlify Deploys

Regarding 4, low-latency is understandable, but again we might not be able to help you port the entire functionality of a Netlify Function into a Netlify Edge Function. The ecosystem is different, runtime is different and the underlying platforms executing those functions are also different. In short, there’s a big difference in those two features, and neither one can completely replace the other, so you should choose the tool based on your specific use-case and preference, rather than just worrying about latency. In most cases, Netlify Functions return data within 1 second even if the request is made from Asia - which is fairly far away from us-east-1.

I’m not trying to say Edge Functions are a bad choice for this project or even overall, just trying to set expectations that, it might not always be the best idea to switch from Netlify Functions to Netlify Edge Functions and vice versa, just because the one of them provides 1 thing better than the other.

Having one of a particular tool, doesn’t necessarily mean that you need to have the entire project in the same tool.

I think you’ve misunderstood what I’ve said, I’m just suggesting that if you’ve built a project using solely Edge Functions and you need to add another dynamic endpoint, for most developers the logical first step/assumption would be to see if it’s possible with edge functions, you’d only deviate if you couldn’t achieve what you needed to (as I have). I’m not saying it “needs” to be the same.

That’s what rewrites are for: Rewrites and proxies | Netlify Docs.

My bad – I hadn’t realised you could now rewrite URLs to point at functions.

I’m not trying to say Edge Functions are a bad choice for this project or even overall, just trying to set expectations that, it might not always be the best idea to switch from Netlify Functions to Netlify Edge Functions and vice versa, just because the one of them provides 1 thing better than the other.

Is there any documentation that defines when what’s better in each or what the long-term goal/vision of each is?

Obviously I understand EFs are in beta and there are different technical limitations (half the memory on EFs, shorter execution time) and certain features aren’t available (e.g. background/scheduled functions are only in Netlify Functions), but the use-cases for Netlify Functions on the marketing site all seem like things Edge Functions could (and possibly should) handle:

Dynamic routes, server-generated content or images, connecting to third-party APIs, custom mircoservices.

To solve your actual issue, did you actually check the beginning of my previous response? If not, let us know what happens when you try that.


Back to your clarifications:

I would think it’s not possible to document such a thing. From what I’ve seen, people like you are trying out various different possibilities. The examples that we’ve created: https://edge-functions-examples.netlify.app/ are probably too basic as compared to what users are actually trying to build. It’s interesting to see what the possibilities are, because we, as a company are trying to learn more about what users want to steer the direction of the production in the correct way.

All of those lines are correct and already being used.

Dynamic routes: it can simply mean creating an endpoint like hello world and show the current time, for example.

server-generated content includes a few server-side rendered frameworks like Nuxt, Svelte, Next.js to some extent, etc.

Connection to third-party APIs is possible as long as you’re able to get the job done within 50 ms of execution time. Execution is the key word, because Edge Functions won’t include time spent on waiting for responses from your API endpoints as “execution time”. So, in most cases, you can get more that 50 ms of time. The problem however is that, since Edge Functions are executed on Deno Deploy, we don’t know exactly what is counted as waiting time and execution time. So, depending on what library or database drivers you might use, it might or might not work.

@hrishikesh sorry I’ve just come back to your suggestion:

I do have some environment variables that I set via the CLI which are present in the Netlify UI:

However, I don’t see anything mentioning a “new experience” or an ability to switch to the old one… this is a screenshot of the header, if that helps identify which I am on?

Hey there, @ryantownsend :wave:

Thanks for following up! Looking at our logs, we are not seeing this error right now.

Can you confirm if you are still encountering obstacles? If you are, please share the URL where you are seeing the error, as well as reproduction steps we need to take to see the error.

Thanks!