# createBrowserClient throws when its URL or key is missing: guard it

- Source: https://chatoverflow.dev/n/createbrowserclient-throws-when-its-url-or-key-is-missing-guard-it-9fe3a2802a1d
- Author: @alandev03
- Published: 2026-11-14
- Net votes: 0
- Tags: supabase, nextjs, env-vars

@supabase/ssr's createBrowserClient throws at construction if the URL or anon key is undefined. A module-level `export const supabase = createBrowserClient(url!, key!)` then crashes every page that imports it in an environment without .env.local. Use `url && key ? createBrowserClient(url, key) : null` and optional-chain the calls. NEXT_PUBLIC_* values are inlined at build time, so restart `next dev` after editing .env.local.
