Short answer
The browser asked for one of your JavaScript files and got HTML back. Usually the visitor has old HTML pointing at chunk files the latest deploy removed, and a catch-all rewrite answers the missing file with index.html. Serve the HTML with Cache-Control: no-cache, as Vite says. We also reload the page on Vite’s vite:preloadError event, and check the base setting if the app lives in a subfolder.
Why the browser got HTML, and the fix
01
Old HTML asks for files the new deploy removed
“When a new deployment occurs, the hosting service may delete the assets from previous deployments.” Vite, Load error handling
A visitor who loaded the page before the deploy still has HTML that points at the old files, which the host may have deleted. Vite says to set Cache-Control: no-cache on the HTML file, so browsers fetch the new one, and shows this event for handling the failed import. We also reload the page there so visitors get the new files:
window.addEventListener('vite:preloadError', (event) => { window.location.reload() // for example, refresh the page })02
The catch-all rewrite answers a missing file with index.html
“This will effectively serve the index.html instead of giving a 404 no matter what URL the browser requests.” Netlify, Rewrites and proxies
Single-page apps usually have a rewrite such as /* /index.html 200 so that links to inner pages work. It also answers a request for a script file that doesn’t exist with index.html, which the browser refuses as a module. Files that do exist are still served, unless the rule ends in an exclamation mark, which Netlify says redirects even when the URL matches a static file. We also check that the rule is the last one in the list.
03
The app lives in a subfolder but base is still /
“Base public path when served in development or production.” Vite, Shared options: base
If the app is served from a path such as /app/, set base to that path in the Vite config, then build again. We also see this when base is left as /: the built HTML asks for files at the site root, and the request gets a page instead of your script.
Checked against the vendor’s docs on : Vite docs: Load error handling; Vite docs: base; Netlify docs: Rewrites and proxies.
Rather hand it over?
Fixed scope, fixed price, paid upfront. The work happens in writing; no call needed.
- from $450App Fix TicketOne reproducible bug in an existing mobile or web app, diagnosed and fixed.See scope and start
- from $450AI-Built App RescueA Lovable, Bolt or Cursor app checked end to end in 3 days, then its worst problems fixed at a fixed price.No issues worth fixing, no charge. If the Launch Check finds nothing rated medium or higher, Simon refunds the full $450. You keep the report either way.See scope and start
Related: Lovable app blank after publishing · Page not found on refresh · Build failed on Netlify or Vercel