Mendlark / Guides

Blank page after deploying a Vite app: how to fix it

Your app built in Lovable, Bolt or v0 works perfectly in the preview. You deploy it to Vercel or Netlify, open the live link, and get a white screen. No error, no content. This is one of the most common go-live problems, and it almost always comes down to a handful of settings. Work through the checks below in order.

1. Open the browser console first

A blank page means the JavaScript crashed or never loaded. The browser tells you which. On a computer, open the live site, right-click, choose Inspect, then the Console tab, and reload. Look for the first red error:

  • Failed to load module script or 404 errors for /assets/index-abc123.js: the files aren't where the page expects them. See steps 4 and 5.
  • supabaseUrl is required, Invalid API key or Cannot read properties of undefined: a missing environment variable. See steps 2 and 3.
  • Unexpected token '<': the server returned your HTML page where a JavaScript file was expected, usually a rewrite rule that catches too much. See step 5.

Also check the Network tab for anything in red. Fixing the first error often clears the rest.

2. Environment variables must start with VITE_

Vite only exposes environment variables to browser code if their name starts with VITE_. Anything else is deliberately hidden, so import.meta.env.SUPABASE_URL is undefined in production even if you set it on your host.

// works
const url = import.meta.env.VITE_SUPABASE_URL
const key = import.meta.env.VITE_SUPABASE_ANON_KEY

// undefined in the browser: no VITE_ prefix
const url = import.meta.env.SUPABASE_URL

// wrong for Vite: process.env is a Node/Next.js pattern
const url = process.env.NEXT_PUBLIC_SUPABASE_URL

Check the exact names your code uses (search the project for import.meta.env), then make sure the same names exist on your host. Spelling and capitals must match exactly.

Lovable and Bolt sometimes manage these values for you inside their own preview, or hard-code them in a generated file. When you export to GitHub and deploy elsewhere, those values don't come with you. Look for a .env or .env.example file in the repo to see which variables are expected.

3. Set them on the host, then redeploy

Vite reads environment variables at build time and bakes the values into the JavaScript files. Changing a variable on Vercel or Netlify does nothing to a site that's already built. You have to build again.

  • Vercel: Project → Settings → Environment Variables. Add each VITE_ variable and tick Production (and Preview if you use it). Then go to Deployments, open the latest one, and choose Redeploy.
  • Netlify: Site configuration → Environment variables. Add them, then Deploys → Trigger deploy → Deploy site.

Because these values end up in public JavaScript, only put public keys here, such as the Supabase anon key or a Stripe publishable key (pk_live_…). Never put a Supabase service_role key or a Stripe secret key (sk_…) in a VITE_ variable: anyone can read it in the browser.

4. Check the build settings and the base path

Your host needs to run the right build and serve the right folder. For a standard Vite app:

  • Build command: npm run build (or vite build)
  • Output directory: dist
  • Framework preset: Vite (Vercel detects this automatically in most cases)

If the output directory is wrong, the host may serve the source index.html, which points at /src/main.tsx and shows nothing.

Next, open vite.config.ts and look for a base option. If your app lives at the root of a domain (https://yourapp.com/), base should be '/' or not set at all. A leftover value like base: '/my-repo/' (common when a project was set up for GitHub Pages) makes the page request /my-repo/assets/…, which doesn't exist, so you get 404s and a blank screen.

// vite.config.ts
export default defineConfig({
  plugins: [react()],
  base: '/', // or remove the line entirely
})

5. Add an SPA rewrite (blank or 404 on refresh)

If the home page loads but refreshing /dashboard or opening a shared link gives a 404 or a blank page, the host is looking for a real file called /dashboard. Single-page apps using React Router need every unknown path sent to index.html so the router can take over.

Vercel: add a vercel.json file to the project root:

{
  "rewrites": [{ "source": "/(.*)", "destination": "/index.html" }]
}

Vercel serves real files (like /assets/index-abc123.js) before applying rewrites, so your scripts still load.

Netlify: create public/_redirects (Vite copies the public folder into dist):

/*    /index.html   200

If you see Unexpected token '<' after adding a rule, check the asset paths from step 4: the browser is asking for a file that doesn't exist and getting index.html back instead.

6. Look for code that only works in the preview

If the variables and paths are right and the console still shows an error, it's likely in the app itself:

  • Case-sensitive imports. Macs and many preview tools ignore capitals; Vercel and Netlify build on Linux, which doesn't. import Header from './components/header' fails if the file is Header.tsx. This usually breaks the build, so check the build log too.
  • Calls to localhost. Search for localhost in the code. A fetch to http://localhost:3000/api works on your machine and fails for everyone else.
  • A crash on first render. Code like user.profile.name before the data has loaded throws an error and React unmounts the whole app. Optional chaining (user?.profile?.name) or an error boundary stops one bug from blanking the entire page.
  • Failed build, old deploy. Make sure the latest deployment actually succeeded. A failed build can leave an older, broken version live.

Quick checklist

  • Read the first red error in the browser console
  • Every browser variable starts with VITE_ and is read with import.meta.env
  • Variables set on the host for Production, then redeployed
  • Build command npm run build, output folder dist
  • base is '/' or not set
  • SPA rewrite added (vercel.json or _redirects)
  • No localhost calls, imports match file names exactly, no secret keys in VITE_ variables

Still stuck?

Mendlark fixes this kind of problem for a fixed €49 (launch price, normally €79). We agree the problem first, test the fix and send it as a pull request, so nothing changes in your app until you merge it. If we can't fix it, you don't pay. Start with a free scan, or read our guide to the Supabase auth redirect loop on Vercel.

Not sure what else is wrong? Paste your app link into the free instant check and get a plain-English list of problems in seconds.