Missing publishableKey
Last verified:
The fix
Missing publishableKey. Clerk has no publishable key at render. Set NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY to a pk_test_ or pk_live_ key, and set CLERK_SECRET_KEY on the server. Restart or redeploy.
- 1
Put both keys in the env file the framework reads
For Next.js, set
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEYandCLERK_SECRET_KEYin.env.local. Development keys arepk_test_andsk_test_. Production keys arepk_live_andsk_live_. Clerk's CLI can write them withnpx clerk@latest env pullfor an existing app. Do not commit the file. Do not prefix the secret withNEXT_PUBLIC_. - 2
Restart, or redeploy
Next.js reads env files at process start. Saving
.env.localwhilenext devis running does not updateNEXT_PUBLIC_values. Stop it and start it again. On Vercel, add both names for the environment you are opening, use the development instance on preview and the production instance on production, then redeploy. A previous deployment keeps the empty value. - 3
Pass the key only if you are not using the default name
ClerkProvider picks up
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEYby itself. PasspublishableKeywhen the variable has another name. An empty expression still throws. Do not hardcode the key in the layout.<ClerkProvider publishableKey={process.env.NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY}> {children} </ClerkProvider> - 4
Do not add clerkMiddleware to fill in a missing key
Middleware does not invent the publishable key. If the error is
auth() was called but Clerk can't detect usage of clerkMiddleware(), the keys may already be set and the matcher is the bug. Fix that page. Do not pastesk_live_into the client to get past either message.
Why it happens
Clerk's client reads the publishable key before it renders. When that value is missing, the thrown text includes Missing publishableKey. One long-standing sentence is @clerk/nextjs: Missing publishableKey. You can get your key at https://dashboard.clerk.com/last-active?path=api-keys. Newer releases phrase the same gap as the keys missing from the environment. The fix is the variables, not a different provider.
Next.js only inlines a public env var that is present when the process starts, and the name has to be NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY. The value starts with pk_test_ for a development instance and pk_live_ for production. Vite uses VITE_CLERK_PUBLISHABLE_KEY. The secret is CLERK_SECRET_KEY, with sk_test_ or sk_live_, and it must not use a public prefix. auth() failing because clerkMiddleware never ran is the other page. A key that is present and then says the middleware was not detected is that page, not an empty variable.
The next error you'll probably hit
Once this is fixed, the usual follow-up is auth() was called but Clerk can't detect usage of clerkMiddleware(). auth() ran on a request that never passed through clerkMiddleware(). The file is in the wrong folder, the matcher skipped the route, or proxy.ts does not export the middleware.
Prompt to paste back into your AI tool
Paste this above the error.
Clerk throws: Missing publishableKey. The full sentence is: <paste> The framework is <Next.js or Vite>. The env file we edited is <path>. Do not commit the key. Do not put CLERK_SECRET_KEY in a NEXT_PUBLIC_ or VITE_ variable. Do not hardcode pk_ or sk_ in a component. Do not add clerkMiddleware as a substitute for the key. 1. For Next.js, require NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY (pk_test_ or pk_live_) and CLERK_SECRET_KEY (sk_test_ or sk_live_). For Vite, the public name is VITE_CLERK_PUBLISHABLE_KEY. 2. Tell me to restart the dev server, or to set both on the host and redeploy. Use development keys on preview and production keys on production. 3. If the error is instead that auth() can't detect clerkMiddleware, stop. That is a different page. 4. Do not print the key values.
Common questions
+The key is in .env.local and the browser still says Missing publishableKey. Why?
The dev server was already running when the file changed, or the name is not NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY. Restart. A public variable with a typo is undefined in the client.
+Vercel has the variable and the deployed site still throws. Why?
The deployment was built before the variable existed, or it is set on a different environment than the URL you opened. Add it for that environment and redeploy. Preview should use the development instance keys.
Related errors
- auth() was called but Clerk can't detect usage of clerkMiddleware()auth() ran on a request that never passed through clerkMiddleware(). The file is in the wrong folder, the matcher skipped the route, or proxy.ts does not export the middleware.Cursorv0BoltAuthNext.jsOct 23, 2026
- process.env.NEXT_PUBLIC_ is undefinedprocess.env.NEXT_PUBLIC_ is undefined. The name is missing from .env.local, it has no NEXT_PUBLIC_ prefix, or Next.js has not been restarted since you added it. Do not put a secret on that prefix.CursorLovableBoltNext.jsVercelNov 3, 2026
- Changed a Vercel env var but the live app still uses the old valueSaving an environment variable does not change the deployment that is already live. Redeploy. NEXT_PUBLIC_ and VITE_ values are copied into the bundle at build time.CursorLovableBoltVercelNext.jsOct 22, 2026
- NEXT_PUBLIC_ secret in the bundleA NEXT_PUBLIC_ or VITE_ secret is in the browser bundle. Rotate the key, move the call to a server route, and keep real public keys in the client.CursorLovableBoltNext.jsViteNov 11, 2026