Description
vite.config.ts does not set the base option. Vite defaults to /, generating asset paths like /assets/main-abc123.js. When the application is served from a subdirectory (e.g., https://example.com/dev-zone/), all asset and chunk URLs are wrong and result in 404 errors, breaking the deployed site.
Steps to Reproduce
- Build the project:
npm run build.
- Serve
dist/ from a web server under /dev-zone/ (e.g., using nginx location /dev-zone/).
- Open
https://<host>/dev-zone/ in a browser.
- Observe the browser console is full of 404 errors for
/assets/... paths.
Root Cause
Without base configured in vite.config.ts, all built asset URLs are absolute from the domain root.
Impact
App cannot be deployed to any non-root URL path, which is a common requirement on shared hosting or GitHub Pages.
Proposed Fix
// vite.config.ts
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
export default defineConfig({
plugins: [react()],
base: process.env.VITE_BASE_URL || "/",
});
Set VITE_BASE_URL=/dev-zone/ in the deployment environment.
Description
vite.config.tsdoes not set thebaseoption. Vite defaults to/, generating asset paths like/assets/main-abc123.js. When the application is served from a subdirectory (e.g.,https://example.com/dev-zone/), all asset and chunk URLs are wrong and result in 404 errors, breaking the deployed site.Steps to Reproduce
npm run build.dist/from a web server under/dev-zone/(e.g., using nginxlocation /dev-zone/).https://<host>/dev-zone/in a browser./assets/...paths.Root Cause
Without
baseconfigured invite.config.ts, all built asset URLs are absolute from the domain root.Impact
App cannot be deployed to any non-root URL path, which is a common requirement on shared hosting or GitHub Pages.
Proposed Fix
Set
VITE_BASE_URL=/dev-zone/in the deployment environment.