Skip to content
>_VibeUnstuck

supabaseUrl is required

Last verified:

The fix

supabaseUrl is required: createClient got an empty URL or key, missing when the bundle was built. Set the Supabase URL and anon key, then rebuild.

  1. 1

    Find every createClient call

    Search the repo for createClient. Keep one module that builds the browser client and import it everywhere else. Delete the extra file that reads a different variable name. Print whether the URL and the key are empty before the call. Do not print the key itself.

  2. 2

    Read the prefix this framework actually exposes

    In Next.js client code, read process.env.NEXT_PUBLIC_SUPABASE_URL and process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY (or the publishable key name that file already uses). A dynamic lookup such as process.env[name] is not inlined. In a Vite app (Lovable and Bolt previews are Vite), read import.meta.env.VITE_SUPABASE_URL and import.meta.env.VITE_SUPABASE_ANON_KEY. Restart vite after any .env change. The Vite env guide says .env files are loaded at startup.

    const url = import.meta.env.VITE_SUPABASE_URL;
    const key = import.meta.env.VITE_SUPABASE_ANON_KEY;
    if (!url || !key) {
      throw new Error("Missing VITE_SUPABASE_URL or VITE_SUPABASE_ANON_KEY");
    }
    export const supabase = createClient(url, key);
  3. 3

    Set the variables where the bundle is built, then rebuild

    On Vercel, add them under Environment Variables. The Vercel docs say a change applies to new deployments, not to one that already built. v0 documents the same variables at Project menu, then Settings, then Environment Variables, and says client-side names need the NEXT_PUBLIC_ prefix. On Netlify, set site environment variables in the Netlify UI, CLI, or API, then start a new deploy. This page does not name a Lovable screen for env vars. The Lovable Cloud docs say that backend does not expose connection credentials. Copy the project URL and the publishable or anon key from the same project, in the dashboard under Settings, then API.

  4. 4

    Keep the secret key off the public prefix

    The value that ships in the bundle is the anon key or the publishable key (sb_publishable_...). The service role key and a secret key (sb_secret_...) do not belong in NEXT_PUBLIC_ or VITE_. Vite's env guide says VITE_ values are bundled into client source and must not contain secrets. An empty string still throws supabaseUrl is required. or supabaseKey is required. Putting the secret key in the client does not fix that, and it publishes the key.

Why it happens

createClient throws before any network call. In current @supabase/supabase-js, validateSupabaseUrl throws supabaseUrl is required. when the URL is missing or only whitespace, and Invalid supabaseUrl: Must be a valid HTTP or HTTPS URL. when it does not start with http:// or https://. The client constructor throws supabaseKey is required. when the key is empty. undefined from a missing env var hits those checks.

Next.js inlines process.env.NEXT_PUBLIC_* when the client bundle is built. A name without that prefix is undefined in browser code, and a value added after the build is not in the bundle you are running. Vite exposes only names that start with VITE_ on import.meta.env, and it statically replaces them at build time. process.env in that browser bundle is the separate process is not defined crash. An AI edit often adds a second createClient that reads SUPABASE_URL while the first file reads VITE_SUPABASE_URL. Lovable's built-in Cloud backend does not expose the project URL or API keys to you. A Cloud app that calls createClient with env vars you were never given fails here. A request that reaches Supabase and returns Invalid API key is a different page: the URL and key were present and did not match.

The next error you'll probably hit

Once this is fixed, the usual follow-up is Invalid API key. Invalid API key. Supabase received a key this project does not accept. Copy the publishable key, or the legacy anon key, from the same project as the URL. No API key found in request means the header was missing.

Prompt to paste back into your AI tool

Paste this above the error.

The app throws "supabaseUrl is required." or "supabaseKey is required." from createClient. The framework is <Next.js or Vite>.

Do not put the service role key or a secret key in NEXT_PUBLIC_ or VITE_. Do not disable RLS. Do not swallow this in an empty catch. Do not hardcode the URL or key in source.

1. Find every createClient. Keep one module. Show me any second file that reads a different variable name.
2. In Next.js client code, read process.env.NEXT_PUBLIC_SUPABASE_URL and the matching public key name. In Vite, read import.meta.env.VITE_SUPABASE_URL and import.meta.env.VITE_SUPABASE_ANON_KEY. Do not use process.env in the Vite browser bundle.
3. If either value is empty, stop and tell me to set it where the bundle is built (Vercel Environment Variables, a Netlify site environment variable, or v0 Project Settings Environment Variables) and to rebuild. A value added after the build is not in this bundle.
4. If this is Lovable Cloud, say so. Those docs say the project URL and API keys are not exposed. Do not invent env names for them.
5. Change only the client module.

Common questions

+The .env file has the URL and the error remains. Why?

The running bundle was built before that variable existed, the name is missing the framework prefix, or a second createClient reads a different name. Next.js inlines NEXT_PUBLIC_ at build time. Vite reads VITE_ from import.meta.env and loads .env files at startup, so restart or rebuild.

+How is this different from Invalid API key?

supabaseUrl is required and supabaseKey is required throw in the browser before the request is sent. Invalid API key means Supabase received a request and rejected the key. Fix the empty value first.

Related errors