Replit app works in preview but not when published

Replit Preview works and publishing fails, or the public URL does not? Check the Publishing logs, production secrets, 0.0.0.0, and the five-second health check.

Reviewed October 17, 2026

What it means in plain English

Run and Preview show the app on a replit.dev URL. Publishing then fails, or the .replit.app URL does something Preview did not. Replit's troubleshooting page says to start with Preview. If Preview is broken, publishing will not fix it.

REPLIT_DEPLOYMENT is 1 in a published project and unset in the editor. REPLIT_DEV_DOMAIN is the replit.dev URL, which is different from the published URL.

Likely causes

  • Preview itself is failing. Replit says to fix the run command, dependencies, errors, ports, and missing secrets there first.
  • The Publishing logs show a stack trace, a missing package, a failed command, a missing environment variable, or a startup error.
  • The run or build command has a typo, a wrong flag, or a wrong entry file, or it only works in the editor.
  • Secrets from the editor are not on the published app. The troubleshooting page says those secrets do not automatically carry over, and to add production secrets and environment variables in the Publishing pane. Missing ones can show up as undefined values, failed API calls, database connection failures, login errors, or payment failures. The Publishing overview says deployment secrets sync from the development environment when you publish or republish. The Secrets page still has a separate list: Publishing, Adjust settings, Production app secrets, and says to review it when testing and production use different credentials. Static Deployments do not get Secrets at all. See Replit works in the editor but Secrets are missing after publish.
  • The program runs once and exits. Published apps expect a long-running process, such as a web server. Replit restarts a program that exits.
  • The server listens on localhost or 127.0.0.1. Published apps have to listen on 0.0.0.0. If .replit lists ports, automatic port detection is off, and one port needs externalPort set to 80. The server has to listen on that localPort. See Replit deployment fails or published app won't load (server must listen on 0.0.0.0).
  • The homepage takes more than five seconds to answer. Replit sends an HTTP request before marking the app live, and that health check can time out.
  • Publishing succeeded and the public URL is still wrong. Replit says to compare production secrets, database connection settings, login callback URLs, payment webhook or redirect settings, API allowlists or CORS, files written on the local filesystem, and mobile layout. Rows you saved in Preview can be missing because the published app uses a different database. See Replit database empty after publish.
  • The deployment type is Static, and the app needs a server, API routes, auth callbacks, or database calls from the server. Replit says to change it to Autoscale. Static issues also come from the wrong public directory.
  • The app is over the size limit. Reserved VM and Autoscale support up to 8 GB. Static supports up to 1 GB.
  • The published filesystem resets every time you publish. Files written only on disk disappear. Replit says to store that data in a database or storage service.
  • A network filter blocks replit.app or replit.dev. Replit's checks are public DNS such as 8.8.8.8 or 1.1.1.1. replit.dev URLs can also change during a cluster migration. After the migration, Replit says they stay stable for about a year unless you request a location change.

A custom domain that fails while .replit.app works is DNS. See Replit custom domain not working.

How to fix it, step by step

  1. Select Run and open Preview. The app should show on a replit.dev URL before you publish.
  2. Open the Logs tab in the Publishing pane and read the startup error.
  3. In the Publishing pane, confirm the build command and the run command match what Preview runs.
  4. Open Publishing, Adjust settings, and review Production app secrets. Publish or republish after they are set. Secrets are unavailable on a Static Deployment.
  5. Make the server a long-running process that listens on 0.0.0.0. If .replit defines ports, include externalPort = 80 and listen on that localPort.
  6. If the health check fails at the last step, move work that makes the homepage take more than five seconds off the first response.
  7. If the app needs a server, set the deployment type to Autoscale.
  8. If only the public URL misbehaves, check production secrets, the database, login and payment redirect URLs, and anything stored only on the local disk.
  9. Paste this to Agent:
This app works in Preview and fails to publish, or the published URL does not match Preview. Do not change product behavior. Check the Publishing logs, the run and build commands, Production app secrets, that the server stays running and listens on 0.0.0.0, any .replit port with externalPort 80, and whether the homepage answers within five seconds. If the deployment is Static and the app needs a server, switch it to Autoscale.

How to check it worked

  • Preview loads.
  • Publishing completes.
  • The public URL runs the main flow.
  • Publishing logs do not show a startup error.
  • In the published app, REPLIT_DEPLOYMENT is 1.

Sources

More Replit fixes

Keep going on your own.

The guides stay free. A deep leak report is $15. Fix packs are $24, or $49 for all three. There is no done-for-you repair.

See products