The built React app is blank, though it works in development
Blank white page after npm run buildShort answer
A blank production page almost always means the browser cannot load the built files. Open the Network tab first. If the script URLs return 404, the base path is wrong for the folder you deploy to. If the page loads on a server but not in an old browser, the build target is too new.
Fix it fast
1Find out which cause you have
Serve the build the way Vite documents it, then read the browser console and Network tab for the first failing request.
npm run build npx vite preview2Match what you see, then jump to its fix
- 1
Requests for /assets/... return 404 while the HTML itself loads from /my-app/.The app is deployed under a sub-path but base is still /Fix - 2
The page works in a current browser but is blank in an older one, with a syntax error in the console.The browser is too old for Vite's default build targetFix - 3
Users with an open tab get import errors right after you deploy.An old deployment's HTML points at asset files that no longer existFix
- 1
What does the error look like?
Blank white page after npm run buildImport errors in the console right after a new deployment
Cause 1 of 3
The app is deployed under a sub-path but base is still /
1Check
Vite uses base as the public path and rewrites asset URLs to match. A project site such as https://user.github.io/repo/ needs base set to /repo/.
grep -n "base" vite.config.*2Fix
Set base to the sub-path, or to ./ so URLs are relative to each file, then rebuild.
// vite.config.js
export default defineConfig({
base: '/my-app/', // or './'
});3Verify
The Network tab shows 200 for every file under the sub-path.
npm run build && npx vite previewConfirmed by vite.dev
Cause 2 of 3
The browser is too old for Vite's default build target
1Check
The default production targets are Chrome 111, Edge 111, Firefox 114 and Safari 16.4 or newer. Vite does not add polyfills.
grep -n "target\|legacy" vite.config.*2Fix
Lower build.target as far as the docs allow, or add the official legacy plugin for browsers without native ESM.
npm install -D @vitejs/plugin-legacy3Verify
The build opens in the older browser.
npm run buildConfirmed by vite.dev
Cause 3 of 3
An old deployment's HTML points at asset files that no longer exist
1Check
Vite advises serving the HTML with Cache-Control: no-cache, so old pages do not reference removed assets.
curl -sI https://example.com/ | grep -i cache-control2Fix
Set no-cache on the HTML file in your server or host settings; keep hashed asset files cacheable.
# nginx
location = /index.html {
add_header Cache-Control "no-cache";
}3Verify
The response headers for / include no-cache.
curl -sI https://example.com/ | grep -i cache-controlConfirmed by vite.dev
How do I stop it coming back?
- Run vite preview before every deploy and read the Network tab once.
- Set base in one place and keep it in sync with the hosting path.
- Deploy HTML with no-cache and assets with long cache times.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- WorkforceA field app, an admin console and a self-hosted Node.js server for push and reconciliation.
Related fixes
Web apps
React shows Attempted import error when importing a component or function
Attempted import error:
The build found the file but not the name you asked for.
2 causes, each with a fixWeb apps
AxiosError Network Error with code ERR_NETWORK in a React app
Network Error
ERR_NETWORK means the request produced no readable response.
4 causes, each with a fixWeb apps
Axios get works with a URL string but ignores the object passed as the second argument
The server log shows a GET with no query string
axios.get takes a URL and an optional config object.
3 causes, each with a fixWeb apps
Can't resolve '../axios' in a React project
Module not found: Error: Can't resolve '../axios'
A path that starts with ./ or ../ is a file path, not the axios package.
3 causes, each with a fixWeb apps
Axios returns 401 from a React app but the login works elsewhere
Error: Request failed with status code 401
A 401 means the server received the request without valid credentials.
3 causes, each with a fixWeb apps
An axios call never finishes when the API server stops answering
code: 'ECONNABORTED'
Axios has no timeout unless you give it one: the default is 0, which means wait forever.
3 causes, each with a fix