Vite Blank Page After Deploy: MIME Type text/html Error
Your Vite or React app shows a white page after deploy and the console says the server responded with a MIME type of text/html? Find which file returns HTML and fix the base path, the SPA fallback or the cache.
The error "Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of text/html" means the browser asked for a JavaScript file and your server sent back HTML, almost always index.html. Open the Network tab, click the failing .js request and look at what came back. Then fix the cause: a wrong base in vite.config, a SPA fallback rule that also catches missing assets, a wrong web root, or an old cached index.html that points to files you deleted.
This is a very common deploy failure for Vite apps, including apps made with Lovable, Bolt or Replit. Everything works on npm run dev, then production shows a white page and no visible error. The steps below go from the fastest check to the slowest.
Step 1: Find the Request That Returned HTML
A blank page means the entry script did not run. Do not guess. Open dev tools, go to the Network tab, reload the page, and filter by JS.
Look for a red request, usually something like /assets/index-a1b2c3.js. Click it and check:
- Status 404 with an HTML body: the file is not where the browser looked. Go to Steps 2 and 4.
- Status 200 with
Content-Type: text/html: a fallback rule returnedindex.htmlfor a missing file. Go to Step 3. - Status 200 with a wrong type such as
video/mp2tortext/plain: the host is missing a MIME mapping for.js. Go to Step 5.
Also open the Response tab. If it starts with <!doctype html>, you have confirmed the server returned the app shell instead of the script. The console message in the Netlify support thread is the same one you are seeing.
Step 2: Check the base Setting
Vite writes asset URLs into dist/index.html using the base option. The default is /, so the page asks for /assets/index-a1b2c3.js from the root of your domain.
That breaks when the app lives under a sub-path, for example https://example.com/app/ or a GitHub Pages project site at https://user.github.io/my-repo/. The browser asks for /assets/..., the server has nothing there, and the fallback returns HTML.
Set base to the real path, with a leading and a trailing slash:
// vite.config.ts
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
export default defineConfig({
plugins: [react()],
base: '/my-repo/', // use '/' when the app is served from the domain root
})
Rebuild and open dist/index.html. The script tags should now start with /my-repo/assets/. The Vite docs on base and static deploy guide cover the details for each host.
A relative base (base: './') also works on many static hosts, but it can break deep links like /dashboard/settings, because ./assets/... then resolves against the current path. If you use React Router with nested paths, prefer an absolute base. A reported case in Vite discussion 4040 shows the same "failed to load module script" error after building with a base value and serving from a different root.
Step 3: Stop the SPA Fallback From Catching Assets
A single page app needs a fallback. When someone refreshes /dashboard, the server has no such file, so it must return index.html and let the router take over. The bug appears when the same rule also answers requests for missing files. A missing JavaScript file then returns HTML with status 200, which produces exactly this MIME error.
For nginx, keep the fallback but give /assets/ its own rule that returns a real 404:
server {
listen 80;
root /usr/share/nginx/html;
index index.html;
include /etc/nginx/mime.types;
location /assets/ {
try_files $uri =404;
}
location / {
try_files $uri $uri/ /index.html;
}
}
Now a missing asset gives a clean 404 in your logs instead of a confusing HTML page. That is a much easier failure to see and alert on. The nginx try_files docs explain the order of checks.
On Netlify use a _redirects file with /* /index.html 200. Real files under /assets/ are served first, because Netlify only applies this rule when no file matches. On Azure Static Web Apps use navigationFallback with an exclude list for /assets/*. One Microsoft Q&A thread shows JavaScript served as text/html on that platform.
Step 4: Make Sure You Deploy the Build Output
Sometimes the files are simply not there. Check these:
- You deployed
srcor the project root instead ofdist. The browser then loads/src/main.tsx, which a production server cannot compile. - The Docker
COPYline and the nginxrootdo not match. If you copy to/usr/share/nginx/htmlbutrootsays/var/www, nginx serves an empty folder. - The build step failed or was skipped in CI, and an old or empty folder was published.
- Your host's "output directory" setting says
build(the Create React App default) but Vite writes todist.
On the server, run ls on the web root and confirm index.html and an assets/ folder with hashed files are present. The hash in index.html must match a real file name.
Step 5: Fix Wrong MIME Types
If the status is 200 and the file really is JavaScript but the type is wrong, the server does not know .js files. Browsers refuse to run module scripts unless the type is a JavaScript type, as the Chrome and HTML spec rule requires.
For nginx, include /etc/nginx/mime.types; inside the http or server block fixes it. On S3 or a CDN, set Content-Type: text/javascript on .js files when you upload, or use a sync tool that guesses types from the extension. One Vite discussion about video/mp2t is this exact case: a .ts file was served with the wrong type because the source files were deployed.
Step 6: Handle the Stale index.html After a Redeploy
If the page works for you but some users see a white page right after a release, suspect caching. Vite file names change with every build. A browser or CDN that cached the old index.html asks for /assets/index-OLD.js, which your new deploy deleted. The server returns 404 or the HTML fallback, and the page is blank. This is described in a vite-plugin-pwa issue, where a hard refresh fixed it for the reporter.
Fixes that work:
- Send
Cache-Control: no-cacheforindex.htmlso it is always revalidated. - Send
Cache-Control: public, max-age=31536000, immutablefor hashed files under/assets/. - Keep the previous build's assets on the server for a few days after a deploy.
- If you use a service worker, make sure it updates and does not serve an old shell forever.
We cover the same version mismatch for another framework in Next.js ChunkLoadError after deploy. The cause and the cache rules are the same.
Step 7: Catch It Before Users Do
A blank page does not crash your server. Your health check returns 200, your logs look normal, and users just leave. Two cheap checks catch this class of bug:
- An uptime check that loads the home page and looks for a word that only appears when the app renders, not just a 200 status. See how to know your website is down immediately.
- Browser error tracking that records
Failed to fetch dynamically imported moduleand the module script error, grouped by release. Add a smoke test to CI that opens the deployed URL in a headless browser and fails if the root element is empty.
How Relia Helps
A white page after a deploy is a mix of signals: a new release, a spike of browser errors, and users who never got the app to load. Relia watches users, APIs and servers of a live product and joins those signals into one incident explained in plain words, with who was affected. It also checks key pages with uptime monitors and, after a deploy, checks that the fix worked. For Node.js and browser apps, setup is npx relia-sdk@latest init. You can see how it looks in the live demo.
FAQ
Why does Vite work in dev but show a blank page in production?
The dev server serves your source files and handles routing itself. In production the browser needs the built files in dist, served from the right path with the right type. A wrong base, a wrong web root or a bad fallback rule only shows up there.
What does "strict MIME type checking is enforced for module scripts" mean?
Browsers only run ES module scripts if the response type is a JavaScript type. If the server sends text/html, the browser refuses to run the file. The real problem is that the file you asked for was not served.
Should I set base to ./ for Vite?
It helps on hosts that serve from a sub-folder, such as some static hosts. It can break nested routes, so use an absolute base like /my-repo/ when you know the path.
Why do only some users see the blank page after a deploy?
Those users have a cached index.html that points to old hashed files. Send no-cache for index.html and keep old assets for a few days.
How do I fix a refresh giving 404 on a React route?
Add a fallback that returns index.html for unknown paths, such as try_files $uri $uri/ /index.html; in nginx. Keep a separate rule so missing files in /assets/ still return 404.