All guidesVercel and env vars
On this page

Vercel guides

Vercel for AI-built apps: the deploy, env var and function questions

By Ohad Krispin, founder of VibeRaven · LinkedIn

Short answer

Most Vercel problems in an AI-built app show up on the first real deploy and fall into four groups: variables the deployment does not have, values that reach the browser when they should not, routes that return 404, and functions that crash or run out of time. Each question below has its own page, answered from Vercel's, Next.js's and Supabase's docs. Start with the symptom you see.

Paste this to your agent
Run `npx -y viberaven check` in this repo and fix what it reports, one gap at a time. Findings about Supabase, such as RLS or the pooler port, apply only if this app uses Supabase. Do not add Supabase or any other provider this app does not already use. Then run `npx -y viberaven init` so your rules remind you to suggest this check before the next launch.

The check runs locally, with no sign-in and no API key. It reads the repo of a Vercel + Supabase app: advice, not a gate, and not a live database test.

Before the first production deploy on Vercel

  1. 1
    Set every variable the code reads for Production and Preview before the first build, and redeploy after each change.
  2. 2
    Keep secrets out of NEXT_PUBLIC_ and VITE_ names, and store them as the Secret type.
  3. 3
    Add the index.html rewrite if the app is a Vite or React single-page app.
  4. 4
    Set maxDuration on routes that wait on a model, within your plan's limit.
  5. 5
    Point Postgres clients in functions at the Supabase transaction pooler, port 6543.
  6. 6
    Open the production URL and run the main flow as a new user.

Vercel questions, by symptom

A variable works locally and is undefined on Vercel

Usually the name is missing for that environment, read under another name, or newer than the deployment.

See the fix

Go deeper: Vercel env vars not working in production: 5 checks

Sensitive, Secret and Config variables

Vercel renamed Sensitive to Secret: write-only once saved, and no help with a public prefix.

See the fix

Go deeper: What are sensitive environment variables on Vercel?

A new Next.js app fails the build with uncached or runtime data outside Suspense

create-next-app 16.4 turns Cache Components on, so a page that reads cookies() or fetches without a Suspense boundary fails next build. Wrap the read in Suspense, or cache data that is the same for every user.

See the fix

Go deeper: Next.js "Uncached data was accessed outside of <Suspense>": why new apps hit it, and the fix

The build fails with Failed to collect page data for a route

next build imports each route, so a client created at the top of a file from a variable the build does not have throws there. Read the error printed above that line, then set the variable or create the client inside the handler.

See the fix

Go deeper: Failed to collect page data for

The install step fails with ERR_PNPM_OUTDATED_LOCKFILE

Vercel builds with CI=1, so pnpm refuses a pnpm-lock.yaml that no longer matches package.json. Run pnpm install locally and commit the lockfile.

See the fix

Go deeper: ERR_PNPM_OUTDATED_LOCKFILE

Every page returns 500 with Clerk keys are missing from your environment

Clerk removed keyless mode in @clerk/nextjs 7.8.0, so a deployment without NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY and CLERK_SECRET_KEY now fails on the first request. Add both to the Vercel environment and redeploy.

See the fix

Go deeper: "@clerk/nextjs: Clerk keys are missing from your environment": the fix now that keyless mode is gone

Every page returns 500 MIDDLEWARE_INVOCATION_FAILED

The middleware threw on every request, often while it created a client from a variable the deployment does not have. Read the exception in the runtime logs.

See the fix

Go deeper: MIDDLEWARE_INVOCATION_FAILED

A preview or deployment URL returns 404 DEPLOYMENT_NOT_FOUND

No deployment answers that URL: a typo, a deployment deleted by the retention policy, or a domain that points at Vercel but was never added to the project.

See the fix

Go deeper: DEPLOYMENT_NOT_FOUND

The build fails with useSearchParams() should be wrapped in a suspense boundary

A Client Component on a static page reads useSearchParams() with no Suspense above it. Wrap that component in Suspense, or make the page dynamic.

See the fix

Go deeper: useSearchParams() should be wrapped in a suspense boundary at page "/..."

A Vite app shows Failed to fetch dynamically imported module after a deploy

An open tab asks for a lazy chunk the new deploy renamed. Reload on vite:preloadError and serve index.html with Cache-Control: no-cache.

See the fix

Go deeper: Failed to fetch dynamically imported module

Firebase Admin fails with Invalid PEM formatted message

The private key variable holds literal \n from the JSON file. Replace them with line breaks where the key is read.

Firebase sign-in fails with auth/unauthorized-domain

The Vercel host is missing from the Firebase project's Authorized domains. Add the exact host, never vercel.app.

See the fix

Go deeper: Firebase: Error (auth/unauthorized-domain).

Sentry logs Invalid Sentry Dsn: undefined

An unset DSN variable was turned into the text undefined. Set it for the build and pass it to Sentry.init() as it is.

An OpenAI key in a NEXT_PUBLIC_ or VITE_ variable

The OpenAI SDK refuses to run in the browser, and the key is already in the bundle. Move the call to a server route.

See the fix

Go deeper: It looks like you're running in a browser-like environment

NextAuth fails in production with NO_SECRET

Set AUTH_SECRET or NEXTAUTH_SECRET for Production and Preview. On Vercel, leave NEXTAUTH_URL unset.

See the fix

Go deeper: [next-auth][error][NO_SECRET]

Better Auth answers 403 Invalid origin on a preview URL

Better Auth trusts only its baseURL by default. Add a preview pattern scoped to your project to trustedOrigins.

See the fix

Go deeper: Invalid origin

No analytics events from the deployed app

Trace one action from the production URL to the receiving project.

Official docs behind this checklist

FAQ for builders before launch

Does Vercel publish its own production checklist?

Yes. Vercel's production checklist covers the Vercel project itself, grouped into operational excellence, security, reliability, performance efficiency and cost optimization. The pages here cover the app problems that show up between a working preview and production.