BreakAlarmLog in

Replit app works in preview but breaks after publish

Preview and the published app are different environments. Preview runs on a replit.dev host with workspace secrets and the development database. The published app is the .replit.app address, or your custom domain, and it uses production secrets and a separate production database. When Preview works and that public URL is blank, returns 500, rejects login, or is missing the data you just created, read the Publishing logs, then Production app secrets, then the production database, then the callback URL registered for the published host. A secret saved in the workspace does not prove the published app has the same value.

Last updated Nov 23, 2026.

A two-minute check

Do this on the published URL. Preview can stay green the whole time, and a private window keeps an old session from hiding a redirect bug.

  1. Open the .replit.app address in a private window. If you connected a custom domain, open that too, in its own tab.
  2. Write down which host fails, and how: blank page, 500, login error, or data that exists in Preview and is absent here.
  3. Try the action that matters. Sign up or log in with an account you create on this URL. An account that exists only in Preview answers a different question.

If the .replit.app address works and only the custom domain fails, publishing succeeded. That host is a domain or callback problem, covered below. If both hosts fail the same way, start with the logs.

Fix it, in this order

Read the publishing logs

Open the Logs tab in the Publishing pane. On a failed publish, open that deployment’s logs and use the first actionable error. The last line often says only that the build failed. Replit’s publishing troubleshooting page tells you to look for stack traces, missing packages, failed commands, missing environment variables, and startup errors.

  1. Match the log time to the request you just made on the published URL. A 500 or 502 is the symptom. The exception, crash, or restart in the runtime logs is the cause.
  2. A homepage that takes more than five seconds to respond can fail the health check Replit sends before it marks the app live. If that is why publish never finishes, move that startup work off the first request.
  3. If the deployment type is Static and the app has API routes, auth callbacks, or database calls, change it to Autoscale in the Publishing pane. Static Deployments serve files. Secrets are not available on them.

Paste this into Agent after you have the log line. It asks for a comparison, and it tells Agent to leave secrets and the production database alone:

The published URL fails and Preview still works. Read the Publishing logs and quote the first real error. Compare Production app secrets with the keys the code reads. Do not print secret values. Tell me whether the published app uses the production database, and whether login redirect URLs include the published host. Do not change the production database. Do not disable authentication.

Set production secrets, then publish again

Workspace secrets and the published app’s secrets are separate lists. Preview reads the Secrets tool: Tools, then Secrets, under Setup. The published app reads the list under Publishing → Adjust settings → Production app secrets. The Publishing overview calls the same section Deployment secrets.

The two Replit pages describe the sync differently, so check the list instead of assuming. The Publishing overview says secrets sync from the development environment when you publish or republish. The publishing troubleshooting page says secrets you set in the Project Editor do not automatically carry over, and tells you to add production secrets in the Publishing pane. Deployment troubleshooting is the practical rule either way: a working Preview does not verify production configuration, and updating a workspace secret does not establish that the published app uses the same value. The running app keeps the values from the last publish.

  1. Open Adjust settings and read every key the published code expects. API keys, the auth secret, and a database URL you added yourself all belong here. If a key is missing, or still holds the development value, set the production value in this list.
  2. If login sets a cookie and the next request is logged out, or startup names a missing secret, find the variable the code uses to sign the session. Add that same key under Production app secrets. Use a long random value, and leave it stable across republishes. Changing it signs out people who already have a cookie.
  3. Select Publish. Then repeat the two-minute check on the published URL. Saving the secret does not restart the app that is already live.
  4. Keep production credentials out of frontend code. A value in client code, or in a variable the browser bundle inlines, ships in the published JavaScript. Database passwords, session secrets, and secret API keys stay in server-side secrets. A publishable key, such as a Clerk key that starts with pk_, is the one the browser is supposed to see. The matching secret key is not.

The production database is not the preview data

Replit gives the app two databases. The development database is what you and Agent use while building. The production database serves the published app. Both environments use a variable named DATABASE_URL, and each has its own value. In the workspace, the Shell, and Agent’s sessions, DATABASE_URL points at development. On current infrastructure it does not even appear in Secrets, because Replit connects it for you. When you publish, the app gets a separate DATABASE_URL that points at production.

Rows you created in Preview are still in the development database. Publishing applies structural changes Agent made, including tables, columns, indexes, constraints, views, and row-level security policies, through drizzle-kit. It does not copy development rows. It also does not copy functions, triggers, or grants. The legacy Neon publish settings have a separate switch, Set up your production database with your current development data, and that copy is optional. On current infrastructure, Replit creates the production database when you publish if the development database contains data. An empty production database looks like a broken app: the account you created in Preview cannot log in, and lists you filled in Preview are blank.

  1. In the Database tool, open the menu next to All Databases and select Production. Open My Data and look for a row you just created on the published URL. Production opens read-only until you turn on editing. A row that exists only in the development database was never going to show up on the published app.
  2. Compare hosts, privately. Open the production database’s Settings tab and find Connection string. Then open Publishing → Adjust settings and find DATABASE_URL under Production app secrets. The host should match, usually the same endpoint id, the part that starts with ep-. A pooled address adds -pooler, so the full strings do not have to be identical. Both values include the database password. Compare them yourself. Do not paste them into a chat, a ticket, or a screenshot.
  3. If Secrets contains a DATABASE_URL you added, that value can point somewhere else. Replit’s built-in connection is not listed there. A NEON_DATABASE_URL secret is the previous development connection, saved during the database upgrade. The app uses it only if the code reads that name. Ask which variable the code actually reads before you delete anything.
  4. If the code reads both DATABASE_URL and the individual PGHOST, PGUSER, PGPASSWORD, PGDATABASE, or PGPORT variables, point them at the same database. Legacy Neon development databases expose those PG variables. Current Replit databases use DATABASE_URL, and the upgrade removes the individual PG variables. A leftover PGHOST in an old secret sends the client at a different database than DATABASE_URL.
  5. Apply schema to production on purpose. A migration you run in the Shell uses the workspace DATABASE_URL, which is development. Publish again so Replit can apply the table and column changes. If the app has its own migration command, run it where DATABASE_URL is the production database, not in the Shell. Seeing REPLIT_ENVIRONMENT=production in the Shell does not mean that Shell is on the production database. The published app is the process with REPLIT_DEPLOYMENT=1.
  6. If the log says the server does not support SSL connections, the client is forcing SSL. Replit’s current development databases do not use it. Neon connections do. Turning SSL off to make Preview connect will break a published app that still expects SSL. Use the conditional setting in Replit’s database docs: SSL off for development, SSL on for production.

Files are a second way for Preview data to vanish. The file system in a published app is not persistent, and it resets every time you publish. Uploads or generated files that live on the workspace disk are absent on the published URL. Store them in the database or a storage service.

Register the published URL with the auth provider

Auth will finish only on a host the provider allows. Preview’s host is the replit.dev address in REPLIT_DEV_DOMAIN. The published hosts are the .replit.app address and any custom domain, listed in REPLIT_DOMAINS. A callback registered for the preview host keeps working in Preview and fails on the URL you published.

  1. Test Preview and the published app separately, and write down the exact error. For an OAuth redirect_uri_mismatch, compare the redirect URI in the error with the URI registered at the provider. Register that exact URI, including https and the path. Do not guess the path, and do not add a wildcard to paper over a mismatch.
  2. On your own Supabase project, open Authentication → URL Configuration. Set Site URL to the published https origin, and add that origin under Redirect URLs. Add the custom domain as well if people use it. The same miss, with localhost left as the Site URL, is the usual Bolt failure. The checks for that host are in Bolt app sign-up works in preview but breaks after deploy. The Lovable version, where the published URL or custom domain is missing from Redirect URLs, is in My Lovable app stopped working.
  3. For your own Google OAuth client, or any other provider you configured, add the published redirect URI in that provider’s console. Copy it from the error or from the request. A domain that works for email and password can still fail the social button until that URI exists.
  4. Replit-managed Clerk is a different setup from a Clerk app you created yourself. Do not mix the two. Managed Clerk has separate Development and Production environments, separate API keys, and separate users. An account you created in Preview does not exist on the published app. Sign up again on the published URL. In the workspace Secrets tool the keys are the test keys. To confirm the published app has the live keys, open Publishing → Overview → Adjust settings and check CLERK_PUBLISHABLE_KEY. The published value starts with pk_live. Leave those keys as Replit set them. Replacing them in the Secrets tool breaks the automatic switch.
  5. If you turned on custom OAuth credentials for managed Clerk, open the Auth pane, then the Configure tab, then Production under SSO providers. The Provider setup checklist lists the values to register in the provider’s console. Copy each one. After you link a custom domain, those values can change. Open the checklist again and register the new ones. Replit Auth is the other built-in option: it uses Replit accounts, and a newly linked custom domain needs another publish so REPLIT_DOMAINS refreshes.
  6. Publish the configuration change, then test in a fresh browser session. An old confirmation or reset link still contains the host it was sent with.

If the .replit.app URL signs in and the custom domain does not, the app is up. Hosting DNS and the auth provider’s allow list are separate checks. Fix the provider for that exact hostname. Replit’s auth troubleshooting says to test the default published URL first, and to avoid deleting an auth tenant to release a domain. Deleting the tenant can delete the accounts.

Hard-coded localhost and preview URLs

Search the project for localhost, 127.0.0.1, and replit.dev. A redirect, a fetch URL, or a CORS origin baked to the preview host sends people from the published app back to the preview machine. Build the URL from the host on the request. REPLIT_DEV_DOMAIN is the development URL. It is a different address from the deployment URL.

  1. The published server has to listen on 0.0.0.0. Listening only on localhost or 127.0.0.1 does not work for published apps. The page stays blank, or the health check never passes. If .replit sets ports, automatic port detection is off: externalPort has to be 80 for the promotion step to pass, and the server has to listen on the configured localPort.
  2. Replace a hard-coded preview origin in redirect and callback code with the origin of the request. Do not paste the production domain into source as the only allowed host. Preview and the published app then each talk to themselves.
  3. Publish again, then repeat the two-minute check on the .replit.app URL and on the custom domain.

How to catch it next time

After every publish, test the published URL. Preview passing is how this bug ships. An uptime ping, including one you write yourself, only proves the URL responded.

The limits are the ones on the pricing section. What is BreakAlarm is the same description. The same preview-versus-published failure on Lovable is in My Lovable app stopped working, and on Bolt in Bolt app sign-up works in preview but breaks after deploy. Other write-ups are on Guides. The homepage runs one check of a public URL you are allowed to test. It does not start the schedule.

Run a free check on your app

FAQ

Why does my Replit app work in the preview but break after I publish it?

Preview and the published app are different environments. Preview uses workspace secrets, the development database, and a replit.dev host. The published app uses production secrets, a separate production database, and the .replit.app host or your custom domain. A working Preview does not verify the production configuration. Open the published URL, then the Logs tab in the Publishing pane, then Production app secrets under Adjust settings.

I updated a secret in the workspace. Why does the published app still ignore it?

The published app reads Production app secrets, under Publishing → Adjust settings. The Publishing overview also calls that list Deployment secrets, and says secrets sync from the development environment when you publish or republish. Updating the workspace secret does not by itself change the app that is already running. Replit’s deployment troubleshooting says a working Preview does not verify production configuration. Set the production value, select Publish again, and test the published URL in a fresh window.

Why is the data I see in Preview missing on the published app?

Those rows are in the development database. The published DATABASE_URL points at the production database, which does not receive your preview rows. Publishing applies structural changes such as tables and columns. It does not copy the development data, unless you used the legacy option to copy development data into production. Accounts created with Replit-managed Clerk in Preview are a separate user store from Production. Sign up again on the published URL. Files written to the workspace disk also disappear on the published app, because that file system resets when you publish.

Login works in Preview and fails on the .replit.app URL or my custom domain. What do I register?

Register the exact published origin: https, the .replit.app host, and the custom domain if you use one. For Supabase, set Site URL and add those origins under Redirect URLs. For your own Google OAuth client or another provider, copy the redirect URI from the error instead of guessing the path. For Replit-managed Clerk with custom OAuth credentials, copy each value from the Provider setup checklist on the Production environment. Test the .replit.app URL before the custom domain. If only the custom domain fails, check that host’s auth allow list, then publish again so REPLIT_DOMAINS includes it.

Will an uptime monitor catch a Replit app that broke after publish?

An uptime check tells you the URL responded. Replit’s app monitoring does that too: it checks that the app is online and emails you if it is down. A page that returns 200 while login fails, the production database is empty, or a button is missing stays green. After every publish, run the flow on the published URL, not in Preview. A Playwright script can walk that flow if you maintain the selectors. BreakAlarm re-walks the steps you describe and emails a screenshot and a paste-ready fix prompt when they fail.

References

Replit, Supabase, Clerk, and Google are trademarks of their owners. BreakAlarm is not affiliated with them.