What this thread does
Do first: run vite build --mode production and compare its selected mode, alias targets and public configuration with the development configuration.
Short answer
As of November 2026, this card targets Vite 8.3.8, released November 11. Vite exposes configuration through import.meta.env; TypeScript paths inform TypeScript import resolution. A missing production value usually needs a prefix/mode/build-input repair followed by a rebuild, while an asset URL under a deployment subpath needs base.
Choose / don't choose
- Explicit Vite alias: choose an absolute filesystem replacement for a shared prefix; don't assume TypeScript rewrites imports (alias contract, TypeScript paths).
import.meta.env: choose nonsecret build configuration; don't put credentials under the public prefix or expect an already-built browser bundle to read newly changed server environment values (env contract).base: choose for emitted asset URLs under a URL subpath; don't expect a router basename to rewrite JavaScript, CSS and HTML asset references. Configure the router's route prefix separately if the app uses one (public base path, router basename).
Not for: choosing an application or library build tool; see vite-8-esbuild-turbopack-webpack-or-tsdown-for-js-builds-2026.
Settings that matter
| Setting or flag | Value / default | Applies to | Source |
|---|---|---|---|
resolve.alias | Map each import prefix to an absolute directory; first defined rules are applied first | Vite 8.3.8 | shared options |
compilerOptions.paths | Match the same prefix and directory; for example "shared/*": ["./src/app/_shared/*"] | TypeScript consumer | TS reference |
envPrefix | Default VITE_; keep an intentional public prefix, never '' | Vite 8.3.8 | shared options |
loadEnv(mode, envDir, prefixes) | Defaults to prefix VITE_; '' loads all env regardless of prefix, so never spread that result into client replacements | Vite 8.3.8 | JS API, config |
mode (overridden by --mode) | Serve defaults to development; build to production; pass actual deployment mode explicitly when different | Vite 8.3.8 | shared options |
base | Default /; /foo/ as an absolute URL pathname, or ./ for embedded deployment | Vite 8.3.8 | shared options, build |
Authored example: use Vite's alias key shared with replacement fileURLToPath(new URL('./src/app/_shared', import.meta.url)), importing fileURLToPath from node:url. This computes an absolute directory relative to the config, while the TS pattern above maps the same shared/... imports. Node documents file URL conversion. TypeScript paths alone do not change emitted specifiers.
Order of operations
1. Choose root, environment directory and mode. Vite evaluates config before automatically loading env files; existing process.env entries are available then. If env values affect configuration itself, call the exported loadEnv helper (config evaluation). Use the actual env directory, which may differ from the current working directory. 2. Keep the public prefix restricted. Never expose a full process environment through define; select any intentional public constants individually. 3. Supply production inputs before invoking the build. Existing process values take precedence over files; mode-specific files override generic files. Restart development after env-file changes, and rebuild production assets after any public configuration change (env loading). 4. Serve the resulting assets at their actual deployment subpath. Inspect an imported asset, CSS URL and browser route directly; each should resolve with the intended public prefix. Use import.meta.env.BASE_URL for composed asset URLs; router basename is the application basename (build path).
Known failures and fixes
| Error (short quote) | Cause | Fix | Source |
|---|---|---|---|
undefined | Client name lacks the public prefix | Inspect the literal import.meta.env property, selected mode and build inputs; keep secrets server-side and rebuild | env contract |
Failed to resolve import | Cause in this app not established; linked report concerns a historical beta regression | Compare exact import to the absolute alias and TS path; inspect the resolved target before rebuilding | alias contract, jrmyio's historical error report |
Sources include jmheretik's February 7, 2021 report. Vite expects to resolve .env files from project root. See jrmyio's February 2, 2024 report; the quoted symptom does not establish that regression in 8.3.8. The alias repair above applies when configuration is the cause.
Missing
- No app-specific prefix, root or deployment subpath is established here. Vite exposes env variables as strings; runtime secret access belongs in server code.
Checked
2026-11-12; Vite 8.3.8. Sources read: Vite release/config/env/build/API pages, TypeScript paths, Node URL conversion, React Router basename, jmheretik and jrmyio reports. No Vite build or deployment commands were run.
Started from a post by @Vite, packaged by the editor. Original post