🔧 Unbreak My AppAll fixesError codesFix KitsSponsor

Fixes › Deploys

App works on localhost but breaks in production: a checklist to find the cause

LovableBoltCursorReplitv0

Published

The error

Works in the preview / on localhost, but the deployed site shows a blank page, 'Failed to fetch', 'undefined' values, 404 on refresh, a login loop, a 500 from an API route, or a webhook that never fires

Why it happens

Your laptop and the AI builder's preview quietly provide things production doesn't. Locally you have a .env file, a dev server that rewrites every route to index.html, a localhost URL that every auth provider already trusts, a lenient dev build that ignores type errors, and a database you're logged into as an admin. In production each of those has to be configured on purpose: environment variables must be added in the hosting dashboard (and frontend ones need the right prefix, such as VITE_ or NEXT_PUBLIC_, at build time), the host needs a rewrite rule for client-side routes, auth providers and Stripe need the real domain, CORS must allow it, and your Row Level Security policies now apply to real signed-in users. Almost every 'works locally' bug is one of these differences, so the fastest fix is to find which one, using the browser console and your host's logs rather than guessing.

How to fix it

  1. Open the live site with DevTools open (Console and Network tabs) and reproduce the problem. Note the first red error and the first failed request (status code and URL). That one line usually tells you which area below it is.
  2. Check your host's logs for the same moment: Vercel → Project → Logs (or Deployments → the deployment → Runtime Logs), Netlify Functions logs, Replit deployment logs, or Supabase → Logs for database, auth and edge functions. A 500 with no detail in the browser almost always has the real error here.
  3. Environment variables: compare your local .env with the variables set in the hosting dashboard for the Production environment. Frontend variables need the framework's public prefix and a redeploy after you change them. Secret keys must stay server-only. 'undefined' in the console or a request to 'undefined/rest/v1' means a missing variable.
  4. URLs: search the code for localhost, 127.0.0.1 and your preview URL. Replace hard-coded values with a config value, and add the production domain to Supabase Auth redirect URLs and Site URL, any Google or GitHub OAuth client, and your Stripe webhook endpoint.
  5. Routing: if the home page works but refreshing or opening a deep link gives 404, the host needs a rewrite of all routes to index.html for a single-page app.
  6. CORS and mixed content: a 'blocked by CORS policy' or 'Mixed Content' error means your API or edge function doesn't allow the production origin, or something is still called over http:// on an https:// site.
  7. Build differences: if the deploy itself fails or the page is blank with a chunk or module error, run the production build locally (npm run build, then preview) and fix the first error it prints, often type errors or an import with the wrong letter case that only matters on Linux.
  8. Data and permissions: if pages load but lists are empty or saves fail, test as a normal signed-in user, not as the dashboard admin. RLS policies, a fresh empty production database, or migrations that never ran are the usual causes.

Fix prompt (paste into Lovable, Bolt, Cursor, Replit or v0)

My app works on localhost / in the preview but breaks after deploying to <HOST, e.g. Vercel / Netlify / Lovable publish / Replit>. The symptom in production is: <DESCRIBE>. The first console error is: <PASTE>. The first failed network request is: <METHOD URL STATUS>. The server log shows: <PASTE or 'nothing'>. Act as a deployment debugger. Compare what local development provides with what production needs and check, in this order: environment variables (names, public prefixes, which are missing in production, and any secret exposed to the browser), hard-coded localhost or preview URLs (auth redirects, OAuth callbacks, API base URLs, webhook URLs), SPA rewrite rules for deep links, CORS and http vs https calls, production-only build errors, and database permissions or migrations that differ between environments. Tell me which one this is, the exact change to make, and which dashboard settings I need to change myself. Don't disable RLS, don't move secret keys into frontend code, and don't delete data.

FAQ

Why does the preview work if production doesn't?

The preview runs a dev server with your local environment and lenient settings. Production is a fresh build on someone else's server with only the settings you've added to the hosting dashboard.

I added the environment variable and it still says undefined.

Frontend variables are baked in at build time, so you need to redeploy after adding them, and the name must have the right public prefix (VITE_ for Vite apps, NEXT_PUBLIC_ for Next.js).

The browser just says 500 or 'Internal Server Error'.

The details are in your host's server or function logs, not the browser. Open the logs for that deployment and look at the timestamp when you reproduced it.

Should I just copy my whole .env into production?

Copy only what production needs, use production values (live keys, the real domain), and never expose secret keys with a public prefix.

Sources

Based on the official documentation:

Related fixes

Want the full checklist for this area? Get a Fix Kit ($29)

Get one new fix a week

Free newsletter: the newest breakages in Lovable, Bolt, Cursor, Replit and v0 apps, with paste-in fixes.

We only use your email to send the newsletter. Unsubscribe any time. See privacy.