SvelteKit + Supabase App : Works fine on local + netlify-cli, fails on deploy

Site name: heartfelt-longma-d0dd9e

Successful deploy preview commit : 56f0835 (server code removed)
Unsuccessful deploy commit see latest production deploy


Running into a rather bizarre bug I can’t seem to figure out with my SvelteKit / Supabase app. I suspect it’s a Supabase issue but I figured I’d start here first since things are only failing on deployment.

Basically, the issue is that for whatever reason, when the app is deployed to Netlify, as far as I can tell, the Supabase code is trying to access the document variable from the SvelteKit server side code. The error appears to be originating from the createSupabaseLoadClient call.

Why, I don’t know but for whatever reason, this ONLY happens on deployment to Netlify, the issue does not occur locally at all. I have also tried using netlify-cli too to double check things but things work on that as well.

I’ve been following this Supabase tutorial to build my app and as far as I can tell I’m doing things correctly; the app otherwise works as expected locally so I’m not sure what the issue could be.

Any help is appreciated. Thank you!

EDIT : To clarify, when I say “this ONLY happens on deployment…” I mean that I only encounter this issue when visiting the deployed site on Netlify. The deployment itself is fine and no errors pop up.

Ok, after a little more testing it seems that setting edge to false in the adapter allows things to work. I had it set to true cause I assumed it would work as I didn’t encounter issues with a different project.

While this is really just a personal project so it’s not absolutely essential that I’m able to use edge functions, I’d still be interested in understanding why I can’t seem to use edge functions with this setup.

Can you attach a link to the failed deploy log?

Apologies if it wasn’t clear, I’ve updated the original post.

To be clear, the deployment is fine, so there isn’t anything to see on that front.

The issue only comes up once you try to visit the deployed site.

I’m not sure if this is something Netlify can help you effectively debug. I can see that in the bundled Edge Function code, you’ve got at least 42 references to document. Some of it is just testing if it’s valid:

some seem to be setting cookies:

and a lot more instances. Overall, it’s a 18k line+ file and the unfortunate truth is, this is all bundled, that is, it includes your code + Svelte’s code + Supabase’s code, so not sure what’s coming from where. You might have debug with with Svelte or Supabase to figure this out.

Apologies for not being clear, I figured you would have looked in the error logs - the reference causing problems seems to consistently happen on the same line from what I can see(though I didn’t look through the whole log), line 8119 as of commit 693c239 of the preview deploys.

I did file a bug with Supabase already, I’ll keep an eye out on that. I just figured I’d start with the Netlify side of things first since this only happens once the site is deployed. For whatever reason, things work fine locally and with the CLI.

I did check that, but those references are to some function calls somewhere else in the code that eventually end up using document. Thus, it’s difficult to find which one it’s actually complaining about.

I’m fairly certain the issue stems from that line though; in that context in Sveltekit, document doesn’t exist yet

But in any case, after looking a bit more into it just now I noticed a strange difference in how edge functions seem to be generated by SvelteKit which might explain why I thought things were fine locally even with the CLI. I will follow up with with the Svelte team.

Thanks for taking a look though! I’m not sure how to do this but it’s fine to consider this closed for now. I’ll pipe back up if some new information comes up where you folks might have more answers.

Here’s the eszip file for your deploy if you want to check it:
644dc1a6fb164b7b867b7ed0.eszip (653.7 KB)

The file can be dropped here: and you would probably want to check the code in render.js file.