Replit app works in preview but not after deploy
Short answer
- Preview and the published app are different environments: different secrets, a different database and a different URL.
- Most breakages come from missing production secrets, an empty production database, hard-coded dev URLs, or callback URLs still set to the dev domain.
- Read the deployment logs first. The first error line usually names the missing piece.
This is the most common complaint on the Replit forum: the app is perfect in the preview and broken at its public URL. Data is missing, API calls fail, login loops, or the page is blank. Replit's documentation sums it up well: it is almost always a configuration difference between environments. Here is how to find which one, in order.
Symptoms
- The published app shows no data, or says No users found, while the preview has everything.
- API calls return 401, 404 or 500 only on the
.replit.appURL or your custom domain. - Login, Stripe checkout or webhooks work in the preview but not live.
- The published page is blank or shows an old version.
Likely causes
- Secrets differ. A key is missing, unsynced or set to a different value for the published app.
- Different database. The published app uses the production database, which starts empty and may lack recent schema changes.
- Hard-coded URLs. Code calls
localhost,127.0.0.1or thereplit.devpreview URL. - Third-party settings still point to dev. OAuth redirect URIs, Stripe webhook endpoints and CORS allowlists.
- Local files. Uploads or generated files were saved to disk, which resets on every publish.
- Wrong deployment type. A full-stack Agent app published as a Static deployment has no server running.
Step-by-step fix
1. Read the deployment logs
Open Publishing, then the logs of the live deployment, and reproduce the bug while you watch. Look for undefined, not set, ECONNREFUSED, relation does not exist or stack traces. Paste the first error into Agent rather than describing the symptom.
2. Compare secrets, key by key
List the secrets your code reads (search for process.env. or os.environ) and check each one in the Secrets section of the Publishing pane. Look for keys that are missing, unsynced, or still set to test values. A secret change only reaches the live app after you publish again. Details in Replit secrets not working in deployment.
3. Check the production database
Open the Database pane and switch to Production. If tables are missing or empty, that explains the missing data: development rows are not copied over. Apply schema changes to production and seed the data the app needs to start (an admin user, settings, plans). See running database migrations in production.
4. Remove hard-coded URLs
Search the code for localhost, 127.0.0.1, replit.dev and http://. Calls from your frontend to your own backend should use relative paths like /api/orders. Absolute URLs your server needs (emails, redirects) should come from one secret such as APP_URL.
5. Update third-party callback URLs
Add the production domain to every external service: Google or GitHub OAuth redirect URIs, Stripe webhook endpoints and success URLs, email links, CORS origins. Each one has its own guide below.
6. Check the deployment type and republish
Agent apps with a backend need an Autoscale or Reserved VM deployment, not Static. Then publish again and test in a private window so you do not see a cached old version.
Copy-paste prompt for Replit Agent
Open a new Agent chat (a fresh chat keeps old attempts out of its context) and paste this:
My app works in the Replit preview but not at its published URL. Help me find the environment difference, without rewriting features.
1. List every environment variable the code reads and tell me which ones must exist in the deployment secrets.
2. Find hard-coded localhost, 127.0.0.1, replit.dev or http:// URLs and replace frontend calls with relative paths and server-side absolute URLs with an APP_URL secret.
3. Check whether the production database has all tables and the seed data the app needs; list what is missing.
4. Find any file writes to the local disk (uploads, generated files) and tell me which ones need App Storage instead.
5. List every external callback URL (OAuth, Stripe, email links) that must be updated to the production domain.
Here are the deployment logs: [paste the first error lines]How to verify the fix
- Run the full user journey on the live URL in a private window: sign up, log in, create a record, pay, log out.
- Deployment logs stay free of errors during that journey.
- Production data survives a republish.
- Repeat the test on your custom domain if you have one.
Before real users arrive, also run through the full production checklist.
FAQ
Does publishing copy my development database?
No. Replit keeps development and production databases separate so test changes do not hit live data. Schema changes need to be applied to production, and data you created in development does not appear there.
Why do I see an old version of my app after publishing?
Either the latest changes were not published yet, or your browser or a cache is serving the old files. Publish again, then test in a private window. See the guide on changes not showing after deploy.
Is it a Replit bug when the deployed app behaves differently?
Sometimes, and the Replit status page lists known incidents. But in most cases the cause is configuration: secrets, database, URLs or callback settings. Check those first.