What you see
Your Vite app (Lovable, Bolt, Cursor or v0 export, or hand-written React) works with npm run dev and even with npm run preview. You deploy it, open the URL, and get a blank white page. The console shows:
Failed to load module script: Expected a JavaScript module script but the server
responded with a MIME type of "text/html". Strict MIME type checking is enforced
for module scripts per HTML spec.
Or the Network tab shows the JavaScript and CSS returning 404 from a path with your repository name in it, like /repo-name/assets/index-CsuQfIM6.css.
This one shows up most when you move hosts: a project first set up for GitHub Pages (which needs a sub-path) gets imported into Vercel or Netlify (which serve from the root), or the other way round.
Why it happens
Vite’s base option is the “base public path when served in development or production”. It defaults to /. During vite build, Vite writes that path into every asset URL: the build docs say JS-imported asset URLs, CSS url() references and asset references in your .html files “are all automatically adjusted to respect this option during build”. So the base is baked into dist/index.html. The host doesn’t get a say.
That gives three ways to break the page:
base: '/repo-name/'on a host that serves from the root. On Vercel, Netlify or Cloudflare Pages your app lives athttps://your-app.vercel.app/, but the HTML asks for/repo-name/assets/index-….js. Nothing is there. In the Vercel Community thread “Vite React App white screen on Vercel deploy”, an app that worked on GitLab Pages showed exactly this 404 (/commercial-cleaning/assets/index-CsuQfIM6.css) on Vercel. In a Netlify forum thread, a Netlify helper spottedbase: '/vite-deploy-demo/'and said: “When deployed on Netlify, the site sits at the domain root/ergo this option is not required (and will break things.)”- No
baseon a GitHub Pages project site. A project site lives athttps://username.github.io/repo-name/. With the default/, the HTML asks forhttps://username.github.io/assets/…, outside your site. Vite’s static deploy guide says to setbaseto'/<REPO>/'in that case, and to'/'(or remove it) forusername.github.ioor a custom domain. - A relative base (
'./') on an app with routes. Vite allows"./"for cases where you don’t know the path in advance, which makes URLs “relative to each file”. In a Netlify forum thread a React Router app worked on the home page but went blank on blog posts. The page source had./assets/index-CdSh20_-.js, so on/posts/…the browser asked for/posts/assets/index-CdSh20_-.js. The site’s SPA rewrite (/* /index.html 200) answered that missing file withindex.html, and HTML is not JavaScript: hence the MIME error. Changingbaseto"/"fixed it.
That last case is why the MIME message is so confusing. When a host rewrites unknown paths to index.html (the fix for 404 on refresh), a wrong asset path returns your HTML page with status 200 instead of a clean 404.
One more variant: if the console complains about MIME type "text/jsx", the host is serving your source files, not the build. In this GitHub issue about a blank Vite app on GitHub Pages, the fix that worked was publishing the built dist folder with a GitHub Actions workflow and setting the right base.
Fix it
1. Read the failing URL
Open the live site, press F12, go to Network, reload. Click the red index-….js request and note its full path. It tells you which case you’re in:
| The browser asks for | Your site is served from | Cause |
|---|---|---|
/repo-name/assets/… |
the domain root (Vercel, Netlify, Pages, custom domain) | leftover base: '/repo-name/' |
/assets/… |
username.github.io/repo-name/ |
missing base for a project site |
/some/route/assets/… |
anywhere | relative base: './' |
2. Set base for the host you deploy to
// vite.config.ts
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
export default defineConfig({
plugins: [react()],
// Vercel, Netlify, Cloudflare Pages, username.github.io, any custom domain:
base: '/',
// GitHub Pages or GitLab Pages *project* site (username.github.io/repo-name/):
// base: '/repo-name/',
})
Start and end the sub-path with a slash, exactly as in Vite’s docs (/foo/), and use the repository name exactly as it appears in the URL.
If you deploy the same repo to two places (GitHub Pages and Vercel), don’t edit the file each time. Vite accepts the option on the command line, vite build --base=/repo-name/, so the GitHub Pages workflow can pass it while Vercel uses the default.
3. Keep the router basename in sync
In the Vercel thread, fixing base made the files load but the page stayed white. The second half of the fix was the router: the app’s React Router basename still pointed at the old sub-path. A Vercel team member had them set it to the root route, and it worked.
Search for basename (usually in main.tsx, App.tsx or a routes file). React Router’s BrowserRouter takes it as the “application basename”:
// Served from the root (Vercel, Netlify, custom domain): no basename
<BrowserRouter>
// Served from username.github.io/repo-name/
<BrowserRouter basename="/repo-name">
If you build URLs by hand (images in public/, fetches to your own files), use import.meta.env.BASE_URL. Vite replaces it at build time with your base. Per the build docs it must appear exactly as written; import.meta.env['BASE_URL'] won’t work.
4. On GitHub Pages, deploy the build, not the repo
GitHub’s publishing source docs offer two modes: deploy a branch as-is, or run a GitHub Actions workflow for sites that need a build step. A Vite app needs the build. Vite’s guide says to go to Settings > Pages, choose GitHub Actions as the source, and use a workflow that runs npm run build and uploads ./dist. If Pages serves the raw branch, the browser gets /src/main.jsx and you see the text/jsx MIME error.
5. Rebuild and redeploy
base only changes on the next build. Run it locally first:
npm run build
grep -o 'src="[^"]*assets[^"]*"' dist/index.html
# root hosts: src="/assets/index-….js"
# GitHub project: src="/repo-name/assets/index-….js"
Then push and let the host rebuild. A prompt for your AI builder: “The deployed app is blank and /repo-name/assets/.js returns 404. Set base in vite.config to ’/’ because we deploy to Vercel at the domain root, remove the React Router basename, and don’t change anything else.”*
Check it worked
- Reload the live URL with the Network tab open: every
index-….jsand.cssrequest returns 200, and the console has no MIME errors. - Open a deep link directly (for example
/dashboard) and reload it. If that 404s, add the SPA rewrite: see 404 on refresh. - If the page still goes blank but the assets load, read the first red console error.
supabaseUrl is requiredmeans your environment variables weren’t in the build. If it only happens right after a new deploy, see Failed to fetch dynamically imported module. - Moved to Vercel and the build itself fails? That’s No Output Directory named dist found. On Netlify, it’s Deploy directory “dist” does not exist.
A page that renders isn’t the same as a page that’s ready for users. Run the free production-readiness checker on your live URL to catch refresh 404s, leftover localhost URLs and keys exposed in your JavaScript. If you’re launching something people will pay for, a written pre-launch audit reviews hosting, auth, payments and Row Level Security for you.