Guides

React (Vite)

Deploy a Vite + React single-page app as static files — settings, build-time variables and the usual failures.

Create the app

  1. 1Apps → New app, then pick the repository. Detection reads package.json, the lockfile and vite.config.*; a Vite app with no server framework comes up as “React single-page app (Vite)”.
  2. 2Choose React Application. Leave “This app runs its own Node server” off — unless the repo also ships an Express server (see Supported app types).
  3. 3Check the build settings it filled in, create the app, and Deploy.

What the repo needs

package.json
{
  "scripts": {
    "dev": "vite",
    "build": "vite build"
  },
  "dependencies": { "react": "^18.3.1", "react-dom": "^18.3.1" },
  "devDependencies": { "vite": "^5.4.0", "@vitejs/plugin-react": "^4.3.0" }
}
  • Commit your lockfile. It decides the package manager: pnpm-lock.yaml → pnpm, yarn.lock → yarn, otherwise npm.
  • Keep Vite’s index.html at the app root so the build writes dist/index.html — a React app without an index.html in its output fails the deploy.

Build settings

Settings → Build configuration
Install command:   npm ci          # pnpm install --frozen-lockfile / yarn install --frozen-lockfile
Build command:     npm run build   # pnpm run build / yarn build
Output directory:  dist
Root directory:    /               # the folder holding package.json, in a monorepo
  • No package-lock.json? npm ci falls back to npm install automatically (the build log says so).
  • Install runs with devDependencies, so Vite and its plugins can stay in devDependencies. The build itself runs with NODE_ENV=production.
  • No server runs. Files are served over HTTPS with SPA fallback: a path that isn’t a file returns index.html, so client-side routes (React Router) survive a reload.

Environment variables

  • Your app’s secrets are passed to the build. Vite only exposes variables prefixed with VITE_ to browser code, and inlines them into the JavaScript at build time:
const apiUrl = import.meta.env.VITE_API_URL;
Anything in a VITE_ variable ends up in the public bundle, readable by anyone — never put a secret key there. Values are fixed at build time, so set them before deploying and redeploy after changing one.

Common failures

  • “No index.html found in the output directory” or “Build output folder … wasn’t found” — the Output directory doesn’t match where the build writes. Vite → dist (or whatever build.outDir says).
  • “Lockfile is out of date” — package.json changed but the lockfile didn’t. Run npm install (or pnpm/yarn) locally and commit the lockfile.
  • “Module … not found” — the package isn’t in package.json, or an import’s capitalisation doesn’t match the file (Linux is case-sensitive).
  • A form POST or fetch to /api/… returns 404 — a static build has no backend. See “Static & React apps have no backend” in the deploy guide.