DEV Community

TestMyLaunch
TestMyLaunch

Posted on

Why Your Bolt App Works in Preview but Breaks in Production

You prompt, Bolt builds, and the preview pane shows a working app. You click Deploy, share the link, and the first message you get back is "it's just a blank page" or "login doesn't work."

Nothing magical broke. The preview and the deployed site are two different environments, and Bolt hides most of the differences from you while you build.

Bolt runs your project inside a WebContainer: a Node.js environment that lives in your browser tab. Your dev server, your API routes, even a small Express backend all run there, and the preview is served from a StackBlitz/WebContainer origin, not from the domain your users will see. When you deploy (to Bolt's own hosting, Netlify, or anything else via GitHub or a download), the app leaves that sandbox. Whatever depended on the sandbox stops working.

Here are the four gaps we see most often, and a five-minute smoke test to catch them.

1. The deployed app still calls the preview (or localhost)

The classic one. Somewhere in the code there's a base URL that was right in the preview and wrong everywhere else:

// works in the WebContainer, fails for every real visitor
const API_URL = "http://localhost:3001";
Enter fullscreen mode Exit fullscreen mode

In Bolt this happens a lot with full-stack prompts. You ask for "a React frontend with an Express API," Bolt starts both processes inside the WebContainer, and the frontend talks to localhost:3001. In the preview that's fine, because both processes are in the same tab. After a static deploy, there is no Express server at all. Only the built frontend got published, and localhost now points at the visitor's own machine.

A variant: the agent copies the preview URL itself (a long *.webcontainer-api.io style address) into a config file or a fetch call while debugging. It keeps working for you as long as your Bolt tab is open, and fails for everyone else.

How to check: open the deployed site, open DevTools → Network, and reload. Every request should go to your own domain or to services you expect (Supabase, Stripe, etc.). Anything hitting localhost, 127.0.0.1 or a WebContainer/StackBlitz host is a bug. Then search the project for those strings and replace them with a relative path (/api/...) or an environment variable.

If your app really needs a backend, decide where it will run in production (serverless functions on your host, Supabase Edge Functions, a separate server) before launch day, not after.

2. Variables that lived in the playground never made it to the host

In Bolt you usually keep keys in a .env file inside the project. The preview reads it, so everything works. But that file doesn't automatically become configuration on the host you deploy to.

Common ways this bites:

  • You push the project to GitHub and connect Netlify or Vercel. .env is (correctly) in .gitignore, so the build runs with no Supabase URL and no anon key. The app loads, then every data call fails.
  • The variable exists on the host, but with a different name. In a Vite project, only variables prefixed with VITE_ are exposed to the browser. SUPABASE_URL in the dashboard and import.meta.env.VITE_SUPABASE_URL in the code means undefined in production.
  • You added the variables on the host after the last build. Vite inlines them at build time, so the live site still has the old (empty) values until you redeploy.

How to check: in the deployed site's console, look for errors like "supabaseUrl is required" or requests going to undefined/rest/v1/.... Then compare, name by name, the keys in your Bolt .env with the ones in your host's environment settings, and trigger a fresh build.

While you're there: anything in a VITE_ variable ends up in public JavaScript. That's fine for a Supabase anon key protected by row level security. It's not fine for a Stripe secret key or an OpenAI key.

3. Refresh on any inner page gives a 404

Bolt apps are usually single-page apps built with Vite and React Router. In the preview, the dev server sends index.html for every path, so /dashboard or /settings/billing always works.

On a static host, a direct visit or a refresh on /dashboard asks the server for a file called dashboard. There isn't one, so the visitor gets the host's 404 page. Clicking around from the home page still works, which is why this slips through: you never type a deep URL while building.

How to fix it on common hosts:

  • Netlify: add a public/_redirects file with one line: /* /index.html 200
  • Vercel: add a rewrite in vercel.json that sends all paths to /index.html
  • Other static hosts: look for "SPA fallback" or "rewrite all routes to index.html" in their docs.

How to check: open an inner page on the live site, press refresh. Then paste that same URL into a new tab. Both should show the page, not a 404.

4. Auth and redirects still point at the editing environment

Login is where preview and production differ the most, because auth providers only redirect to URLs you explicitly allow.

While building in Bolt, you (or the agent) set up Supabase Auth, Google sign-in or magic links using whatever URL was in front of you: the WebContainer preview or http://localhost:5173. Then:

  • Magic link and confirmation emails send people to the preview URL, which doesn't work for them.
  • Google OAuth fails with a redirect mismatch because only the preview origin was added as an authorized redirect URI.
  • Password reset lands on a page that only exists in the editor.
  • After login, the code does window.location.href = "http://localhost:5173/dashboard".

How to check: in Supabase → Authentication → URL Configuration, set the Site URL to your production domain and add it to the redirect allow-list. Do the same in the Google Cloud console (or whichever OAuth provider you use). Search the code for hardcoded localhost and preview URLs in redirect options like emailRedirectTo or redirectTo, and switch them to window.location.origin or an env variable.

Then sign up with a fresh email on the live site and follow the email link to the end.

A five-minute smoke test in a private window

Do this on the deployed URL, not in Bolt, and in a private/incognito window so no editor session, cookie or cached login helps you:

  1. Home page: loads, no red errors in the console, no requests to localhost or WebContainer hosts in the Network tab.
  2. One inner route: navigate to it, then paste its URL into a new tab.
  3. One refresh: press refresh on that inner page. No 404.
  4. One form: submit something real (sign-up, contact, create an item) and confirm it actually saved, not just that a success toast appeared.
  5. One phone: open the same URL on your actual phone, on mobile data if you can. Tap the main button and open the menu.

If all five pass, the most common "works in preview, broken in production" problems are behind you. If one fails, it's usually one of the four gaps above.

Wrapping up

The Bolt preview is a great place to build, but it's a friendly environment: your processes, your .env, your session, a dev server that forgives every route. Your users get none of that. Testing the deployed URL the way a stranger would is the cheapest launch insurance there is.

If you'd like a second pair of eyes, we built a free scan that opens your live app in a real browser on mobile and desktop, follows links, clicks safe buttons and watches the console, then gives you a score out of 100 and what it found. No card needed.

👉 https://testmylaunch.com?ref=devto

What broke the first time you deployed a Bolt app? Share it in the comments.

— The TestMyLaunch Team

Top comments (0)