网页 综合 更新时间 2026-10-18 23:52:10

"Invalid API key" or undefined env vars on Vercel: how to fix it - DEV Community

自动蜘蛛 dev.to 正文约 1878 字
"Invalid API key" or undefined env vars on Vercel: how to fix it - DEV Community
Posted on Oct 18 • Edited on Oct 30 • Originally published at unbreakkit.netlify.app
Your app works on your machine. You deploy to Vercel and get one of these:
Or process.env.MY_KEY is simply undefined in production.
Vercel → Project → Settings → Environment Variables. Add each key, tick the environments that need it, then redeploy (Deployments → ⋯ → Redeploy). Or use the CLI:
Public prefixes are baked in at build time, which is another reason a redeploy is required.
Secret keys (SUPABASE_SERVICE_ROLE_KEY, OPENAI_API_KEY, STRIPE_SECRET_KEY) must not get a public prefix. Anything with NEXT_PUBLIC_ or VITE_ ends up in the JavaScript sent to every visitor. Use secrets only in Route Handlers, Server Actions or API routes:
For NEXT_PUBLIC_ variables in client code, reference them literally (process.env.NEXT_PUBLIC_X). Dynamic lookups like process.env[name] aren't inlined in the browser.
Re-copy the key from the provider dashboard. Remove quotes and trailing spaces. Make sure it's the key for the right project (for example, the Supabase anon or sb_publishable_… key in the client, never the service role or sb_secret_… key).
I added it but it's still undefined. Did you redeploy? Is it ticked for Production?
Is the Supabase anon key safe to expose? It's designed to be public, but only if Row Level Security is enabled on your tables.
Originally published on FixKit AI. Deploy failing for a different reason? See why v0/Bolt apps fail on Vercel, or paste the error into the free FixKit Error Fixer (disclosure: I built it).
DEV Community — A space to discuss and keep up software development and manage your software career
Built on Forem — the open source software that powers DEV and other inclusive communities.
Made with love and Ruby on Rails. DEV Community © 2016 - 2026.
We're a place where coders share, stay up-to-date and grow their careers.
访问原文 返回搜索 https://dev.to/unbreakkit/invalid-api-key-or-undefined-env-vars-on-vercel-how-to-fix-it-50ig
本页为82搜索生成的网页快照,内容来自站内索引;演示数据的原文链接仅作示例。