Deploying React + Vite to GitHub Pages: Fixing the Classic 404 Asset Path Error
A quick troubleshooting guide for deploying Vite + React apps to GitHub Pages without blank screens or 404 asset errors by configuring base in vite.config.ts.
When deploying React + Vite projects (like tuh-doo) to GitHub Pages, it is super common to run into a blank white screen with 404 errors for /assets/index-xxx.js even though everything worked locally.
Why Does the 404 Happen?
Locally, your app runs at root (/). On GitHub Pages project URLs, it is served under a repository subpath like https://username.github.io/tuh-doo/. Without telling Vite about that subpath, index.html requests /assets/... from the root domain and misses every bundle file.
One-Line Fix in vite.config.ts
Set base to match your repository path:
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
export default defineConfig({
plugins: [react()],
base: "/tuh-doo/",
});Extra Tip for Client Routing
Because GitHub Pages only serves static files, if your Vite app has multiple client-side routes, either use HashRouter or duplicate index.html as 404.html during deploy.
Final Thoughts
A single config line saves a lot of head-scratching on your first GitHub Pages Vite deployment.
Miguel Riquelme
Front-end Engineer. Software Engineering MBA student at USP/Esalq.