Why Does My App Work Locally but Break When Deployed?
Your live app is a separate copy with its own settings. The usual causes are missing environment variables, sign-in redirects still pointing at localhost, a database that didn't get your latest changes, and files that don't persist. Check them in that order, reading your host's logs first.
This app works in [preview / local] but fails at [production URL]. What happens: [exact symptom and the steps to reproduce it]. Browser console error: [paste, with tokens removed]. Server log: [paste from my host's logs, with secrets removed]. Compare the two environments. Check, in this order: 1. Environment variables: list each one the code reads, and whether it's needed at build time or run time. Tell me which to check on my host. Don't ask for the values. 2. Sign-in: site URL and redirect URLs. 3. Database: have all migrations been applied to production? Give me a read-only way to check. 4. Webhook endpoints, allowed origins, and any hardcoded localhost addresses. 5. File storage, background work, ports and start commands. Don't change code until you've told me the most likely cause and the safest next check. Don't suggest disabling any security rule.
- 1Read your host's logsThey name the failure
- 2Environment variablesUndefined values, or set but not redeployed
- 3Sign-in redirectsEmails that open localhost
- 4Database changesTables production doesn't have yet
- 5File storageUploads that vanish after publishing
Try it now
- 1Read the logs first. On Vercel, open Logs in the sidebar, and filter by Error. On Replit, open the Publishing pane and its Logs tab. Open the browser's Console panel too.
- 2Compare your variables with the list the prompt gives you. On Vercel, check in the project's settings that each one is set for Production, then redeploy.
- 3On Supabase, check URL Configuration under Auth. It's fixed when the failing steps work in a private window on your real domain, signed in as a new user.
Use it when
When the app works in your preview and fails at its real address, or a deployment fails. Replit's order is a good start: if it doesn't work in Preview, fix that first, since publishing won't fix a broken app.
Skip it when
If the app is broken everywhere, use the debugging card instead. And don't "fix" a production failure by copying your development database or test keys into production. That hides the error and creates a worse one.
Why it works
Vendors document these causes because they're so common:
- Missing variables: Replit says secrets from the editor don't carry over to a published app. Add them in the Publishing pane. Symptoms include undefined values, failed API calls, and login or payment errors.
- Stale variables: Vercel applies changes only to new deployments, so redeploy. Next.js freezes
NEXT_PUBLIC_values at build time. - Sign-in: Supabase uses Site URL as the default redirect, and it says to change it from
http://localhost:3000. AnyredirectTomust match your allow list. - Database: a local or development database has tables production doesn't, until your migration runs. On Replit, publishing applies the changes after you approve them.
- Files: Replit says the published file system isn't persistent and resets each time you publish, so uploads need a database or storage.
- Network: Replit says the server must listen on
0.0.0.0, notlocalhost. - Webhooks: the address changes when you go live, and Stripe's signing secret differs per endpoint.
Example
Sign-in works in preview. In production, clicking the confirmation email opens localhost:3000 and fails. The cause is Supabase's Site URL, still set to its default. You change it to https://www.example.com and add the exact callback path to the redirect list.
A second bug follows: the app's AI feature returns 500. The Vercel logs show the API key as undefined. The variable was only set for Preview. You add it for Production and redeploy, since the running deployment keeps the values it was built with. Each fix takes a minute once the log tells you where to look.
Going further
Reproduce production on your own machine before deploying. Next.js suggests running next build, then next start, which catches build errors that a development server hides. vercel env pull downloads your Development variables, so .env.local matches what's on the host, though it doesn't pull Production values by default.
Some variables behave differently by environment. Dynamic lookups such as process.env[name] aren't inlined by Next.js, so they come out undefined in the browser even with the right prefix. On Vercel, code that branches on VERCEL_ENV sees preview in custom environments, and VERCEL_TARGET_ENV gives the real name.
Replit has a quiet trap: .replit port settings turn off automatic detection, so externalPort must be 80. Its docs also give a prompt for Agent that compares Preview and production behavior, which is worth trying before you debug by hand.
Common mistakes
- Adding a
NEXT_PUBLIC_prefix to a secret to make it work in production. This fixes the error by publishing the key. - Changing a variable and retesting without redeploying.
- Pasting logs into a chat with tokens or keys still in them. Remove them first.
- Pointing production at your development database because it has the right tables. Apply the migration instead.
Sources
- Troubleshoot publishing, Replit docs
- Development and production databases, Replit docs
- Environment variables, Vercel docs
- Runtime Logs, Vercel docs
- Environments, Vercel docs
- Environment variables, Next.js docs
- Production checklist, Next.js docs
- Redirect URLs, Supabase docs
- Webhooks, Stripe docs
Checked 6 November 2026. Products change often, so confirm details with the vendor.