Replit app works in Preview but publishing fails or the live URL is broken
Updated 2026-11-11
What you see
Everything runs in the Replit Preview pane. You hit Publish, and either the publish fails near the end, or it succeeds but the public replit.app URL shows errors, blank data or failed logins.
Replit’s own troubleshooting guide starts with one rule: if Preview is broken, publishing will not fix it. Get Preview working first, then go through the checks below in order.
1. Your server listens on localhost
Replit says published web servers must listen on 0.0.0.0. A server bound to localhost or 127.0.0.1 does not work once published.
// Express
app.listen(process.env.PORT || 3000, '0.0.0.0');
# Flask
app.run(host="0.0.0.0", port=int(os.environ.get("PORT", 5000)))
If you have ports defined in .replit, automatic port detection is turned off. You then need a port entry with externalPort = 80 that maps to the localPort your server actually uses.
2. Secrets didn’t come with you
Replit notes that Secrets set in the Project Editor do not automatically carry over to the published app. Add every API key, database URL and auth secret in the Publishing pane. If you skip this, you get undefined values, failed API calls, database connection errors and broken logins in production only.
3. The homepage is too slow for the health check
Before an app goes live, Replit requests your homepage. If it takes more than five seconds, the health check can time out and publishing fails at the final step. Move slow startup work (migrations, warm-up fetches, large data loads) out of the request path.
4. The program exits
Published apps are expected to keep running. A script that runs once and exits gets restarted over and over. Make sure the run command starts a long-lived web server.
5. Wrong deployment type
Static Deployments serve only HTML, CSS and JS files. If your app has API routes, auth callbacks or server-side database calls, switch to Autoscale in the Publishing pane.
Also check
- Files disappear: the published file system resets on every publish. Store uploads and data in a database or object storage, not on local disk.
- Login redirects and payment webhooks still point at the
replit.devpreview URL. Update them to the published URL at your auth and payment providers. - Read the Logs tab in the Publishing pane. The real error is usually printed there.
Check it worked
Open the published URL in a private window, sign in, and run the main flow once end to end. Then add a free uptime monitor so you hear about it the next time it breaks.