Search code examples
reactjstypescriptvitesupabase

Can't deploy react with typescript, vite and supabase in netlify


No problem in my local development but i cant deploy it using netlify and it throws an error:

Uncaught Error: supabaseUrl is required.

My supabaseConfig file:

import { createClient } from '@supabase/supabase-js'
const supabaseKey = import.meta.env.VITE_SUPABASE_API_KEY;
const supabaseUrl = import.meta.env.VITE_SUPABASE_URL;
const supabase = createClient(supabaseUrl, supabaseKey)
export default supabase

Here's my .env variables:

VITE_SUPABASE_API_KEY="mySupabaseApiKey"
VITE_SUPABASE_URL="mySupabaseUrl"

My .env is in the root directory, i also installed the dotenv package, i searched but still cant resolve this issue.


Solution

  • You need to add your environment variables to the Netlify dashboard for this to work. You can read more about how to do this from the Netlify documentation website https://docs.netlify.com/environment-variables/overview/