It works in preview, but not when deployed. Why?

The preview runs inside your builder, with its settings, its keys and its test data. The live app runs somewhere else and only gets what you gave it there. Most of the time one of five things is missing: your secret keys, the right network address, the real database, files you saved locally, or a setting that still points to the preview address. Check them in the order below.

Last checked 3 December 2026

Start with the live app's logs

Before changing anything, open the logs of the live app (in your builder's publishing screen, or on your server). The first error there usually names the missing piece: an empty key, a refused connection, a file that is not found.

Five things to check

  1. Your secret keys did not come with you.

    Keys you add in the editor are often kept apart from the live app. Replit, for example, says secrets you set in the editor "do not automatically carry over" to the published app, and missing secrets cause "errors about undefined values, failed API calls, database connection failures". Add them again where the live app runs. Full walk-through: My API keys didn't reach the server.

    Source: Replit Docs, "Troubleshoot publishing"

  2. The app listens on "localhost".

    "localhost" means "this computer only". It works in preview and fails once the app is published. A published app must listen on 0.0.0.0, which means "any address".

    Source: Replit Docs, "Troubleshoot publishing"

  3. The live app still uses the test database.

    Builders often start you on a test database. Check which database the live app connects to, and that its address and password are set in the live app, not only in preview.

    Source: Replit Docs, "Troubleshoot publishing"

  4. Files you saved inside the app disappear.

    On some platforms the published app's disk is wiped every time you publish. Uploads and data saved as files vanish. Keep them in a database or a storage service.

    Source: Replit Docs, "Troubleshoot publishing"

  5. Something still points to the preview address.

    Login redirect addresses, payment webhooks and lists of allowed websites (CORS) are set per address. Add your live address to each of them.

    Source: Replit Docs, "Troubleshoot publishing"

Common mistakes

  • Changing code before reading the logs. The error message usually says what is missing.
  • Fixing it in preview again. Preview already works. The fix belongs in the live app's settings.
  • Putting a secret key in browser code to "make it work". Anything the browser gets, every visitor can read. See My API keys didn't reach the server.

Limits

  • The examples come from Replit's documentation. Other builders name these settings differently; look for "secrets", "environment variables" or "publishing settings".
  • This guide does not fix code errors that also happen in preview.
  • ANAROQ does not host your app.

Related pages