← 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

The browser blocked the response because the Edge Function did not return CORS headers, often on the OPTIONS preflight request.

Likely causes

How to fix it

  1. Handle preflight and add headers to 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' },
      });
    });
  2. Redeploy the function: `supabase functions deploy <name>`.

Prevent this next time

Guide: catch outages before your users do.

FAQ

What does "TypeError: Failed to fetch (Supabase Edge Function / CORS)" mean?

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. Handle preflight and add headers to every response: 2. Redeploy the function: `supabase functions deploy <name>`.

Related errors

Get new fixes weekly

No spam. Unsubscribe anytime. Privacy