Clerk: publishable key is missing. Why it happens and the fix that does not expose your secret key
Your app loads and Clerk throws an error that the publishable key is missing. Nothing renders, or sign-in is dead. This is almost always a configuration problem, not an attack. What it means The frontend did
Your app loads and Clerk throws an error that the publishable key is missing. Nothing renders, or sign-in is dead. This is almost always a configuration problem, not an attack.
What it means
The frontend did not receive Clerk's publishable key. The usual causes:
- The environment variable is not set in the environment you are running (local, preview or production).
- The variable name does not match what your framework exposes to the browser. In Next.js it must start with
NEXT_PUBLIC_. In Vite it must start withVITE_. - The value was added after the last build, and your framework inlines it at build time. You need to redeploy.
- Clerk is initialized with the wrong or an empty value.
The fix
- Copy the publishable key from your Clerk dashboard for the right instance (development or production).
- Set it under the name your framework expects, for example
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEYin Next.js. - Redeploy so the build picks it up.
- Sign in, then open a private route to confirm it works.
The mistake to avoid
Do not "fix" it by putting the secret key in the front end. The publishable key is designed for the browser. The secret key belongs only on the server, for backend calls. If a secret key ever reaches your JavaScript, rotate it in the Clerk dashboard and move it to a server-side environment variable.
Client: publishable key only
Server: secret key only, where backend calls need it
Check your live site
After deploying, look at the JavaScript your site serves. You should see a publishable key (it starts with pk_) and no secret key (sk_). Free read-only check for a site you own: https://proofforge.live/tools/exposed-api-key-checker
Full guide: https://proofforge.live/errors/clerk-missing-publishable-key . Related: a secret key reported as missing on the server side: https://proofforge.live/errors/clerk-missing-secret-key
Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes β full credit and traffic to the original publisher.