Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Next.js and React

The built React app is blank, though it works in development

ErrorBlank white page after npm run build

Short 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.

  • Applies to Vite 7, React 19, Node.js 22
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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 preview
  2. 2Match what you see, then jump to its fix

    1. 1Requests 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. 2The 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. 3Users with an open tab get import errors right after you deploy.An old deployment's HTML points at asset files that no longer existFix

What does the error look like?

  • Blank white page after npm run build
  • Import 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 preview

Confirmed by vite.dev

Did this fix it?

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-legacy

3Verify

The build opens in the older browser.

npm run build

Confirmed by vite.dev

Did this fix it?

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-control

2Fix

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-control

Confirmed by vite.dev

Did this fix it?

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:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.