Error: supabaseUrl is required
Error: supabaseUrl is required.
at new SupabaseClient
at createClientIn one sentence: createClient() got undefined for the project URL, which almost always means the environment variable isn't set, isn't loaded, or isn't exposed to the browser.
What it means
`createClient(url, key)` needs your project URL and anon (public) key. When `process.env.NEXT_PUBLIC_SUPABASE_URL` (or the Vite equivalent) is undefined, Supabase throws this error as soon as the file loads. The sibling error `supabaseKey is required` means the same thing for the key.
It often works on your machine and breaks after deploy, because `.env.local` is never uploaded to Vercel, Netlify or similar hosts.
Common causes
- The variables are missing from your host's environment settings (Vercel → Project → Settings → Environment Variables).
- The name lacks the public prefix the browser needs: `NEXT_PUBLIC_` in Next.js, `VITE_` in Vite (read with `import.meta.env`).
- The env file is in the wrong folder or has the wrong name, or the dev server wasn't restarted after editing it.
- A typo between the variable name in the file and the one in code.
- Variables were added on the host but the site wasn't redeployed, so the build still has the old values.
How to fix it
- Check the names match exactly in your env file and code, for example `NEXT_PUBLIC_SUPABASE_URL` and `NEXT_PUBLIC_SUPABASE_ANON_KEY`.
- Put `.env.local` in the project root (next to `package.json`) and restart the dev server.
- Add the same variables in your hosting dashboard for Production (and Preview if you use it), then redeploy.
- Only the URL and anon key should be public. Never give the `service_role` key a `NEXT_PUBLIC_` or `VITE_` prefix.
- Add a clear check so a missing value fails with a readable message instead of a crash deep inside the library.
Before
export const supabase = createClient(process.env.SUPABASE_URL, process.env.SUPABASE_KEY);After
const url = process.env.NEXT_PUBLIC_SUPABASE_URL;
const key = process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY;
if (!url || !key) throw new Error("Missing NEXT_PUBLIC_SUPABASE_URL or NEXT_PUBLIC_SUPABASE_ANON_KEY");
export const supabase = createClient(url, key);Tried this and it's still broken? Paste your exact error for a free explanation of your specific case.
Prompt to paste into your AI tool
My app crashes with 'supabaseUrl is required'. Find where createClient is called, make sure it reads correctly prefixed public env vars (NEXT_PUBLIC_ for Next.js or VITE_ via import.meta.env for Vite), add a clear error if they're missing, and list the exact variables I need to add to .env.local and my hosting dashboard. Never expose the service_role key. Don't change unrelated code.Still stuck?
Paste your exact error and code. Get a plain-English explanation free, or the full fix for $5.
Hitting errors every day? Builder is $15/mo for 100 fixes per month. Compare plans
Related errors
- Error: NEXT_REDIRECT
- TypeScript: Type 'string | undefined' is not assignable to type 'string'
- git push rejected: failed to push some refs
- TypeError: Cannot read properties of undefined
Weekly: the errors breaking vibe-coded apps and how to fix them. Free.
No spam. Unsubscribe anytime.