← All errors · SupabaseServerless & Edge Function errors
TypeError: Failed to fetch (Supabase Edge Function / CORS)
Exact error
Access to fetch at 'https://<ref>.supabase.co/functions/v1/...' has been blocked by CORS policy
What it means
AI tools such as Lovable, Bolt, Cursor, and v0 often scaffold a Supabase Edge Function without CORS handling, so the browser blocks the call. The browser blocked the response because the Edge Function did not return CORS headers, often on the OPTIONS preflight request.
See also: official Supabase guide: Unable to call Edge Function.
Likely causes
- Edge Function doesn't handle the OPTIONS method.
- CORS headers missing on success or error responses.
How to fix it
If the project uses @supabase/supabase-js v2.95.0 or later, import the official CORS headers so they stay in sync with the client, and handle OPTIONS on every response (this is the approach in the official Supabase guide):
import { corsHeaders } from '@supabase/supabase-js/cors'; // v2.95.0+ Deno.serve(async (req) => { if (req.method === 'OPTIONS') return new Response('ok', { headers: corsHeaders }); const data = { ok: true }; return new Response(JSON.stringify(data), { headers: { ...corsHeaders, 'Content-Type': 'application/json' }, }); });On older supabase-js versions, hardcode the headers and still handle OPTIONS on every response:
const corsHeaders = { 'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Headers': 'authorization, x-client-info, apikey, content-type', }; Deno.serve(async (req) => { if (req.method === 'OPTIONS') return new Response('ok', { headers: corsHeaders }); const data = { ok: true }; return new Response(JSON.stringify(data), { headers: { ...corsHeaders, 'Content-Type': 'application/json' }, }); });Redeploy the function: `supabase functions deploy <name>`.
If an AI tool wrote the function, paste this so it adds CORS handling and redeploys:
The browser blocks my Supabase Edge Function with a CORS / Failed to fetch error (Access-Control-Allow-Origin). Update the function to handle OPTIONS preflight and return CORS headers on every response. If @supabase/supabase-js is v2.95.0 or later, import corsHeaders from '@supabase/supabase-js/cors'. Then redeploy the function.
Still stuck after trying this? Get it fixed for $49, or you don't pay.
Prevent this next time
- Add timeouts to outbound requests and return clear error responses instead of crashing.
- Set up uptime checks and log alerts on critical endpoints so you hear about failures before users do.
Guide: catch outages before your users do.
Tools that help:
- Better Stack: Uptime, cron/heartbeat monitoring and log alerts.
Some links on this page are affiliate links: if you sign up or buy through them, FixStack may earn a commission at no extra cost to you. Learn more.
FAQ
What does "TypeError: Failed to fetch (Supabase Edge Function / CORS)" mean?
AI tools such as Lovable, Bolt, Cursor, and v0 often scaffold a Supabase Edge Function without CORS handling, so the browser blocks the call. The browser blocked the response because the Edge Function did not return CORS headers, often on the OPTIONS preflight request.
What usually causes it?
Edge Function doesn't handle the OPTIONS method. CORS headers missing on success or error responses.
How do I fix it?
1. If the project uses @supabase/supabase-js v2.95.0 or later, import the official CORS headers so they stay in sync with the client, and handle OPTIONS on every response (this is the approach in the official Supabase guide): 2. On older supabase-js versions, hardcode the headers and still handle OPTIONS on every response: 3. Redeploy the function: `supabase functions deploy <name>`. 4. If an AI tool wrote the function, paste this so it adds CORS handling and redeploys:
Last checked against official docs on . Sources: Official Supabase Knowledge Base: Unable to call Edge Function.
Related errors
More Supabase errors and fixes →
Tools that help
- Railway: Deploy backends and databases; new users get $20 credit.
Some links on this page are affiliate links: if you sign up or buy through them, FixStack may earn a commission at no extra cost to you. Learn more.
Get new fixes weekly
No spam. Unsubscribe anytime. Privacy