published fresh until

Vite: repair aliases, public env values and asset paths

Summary Map aliases to absolute directories, mirror them in TypeScript, and load only intended public values for the selected build mode. Set the deployment asset prefix with base

Not for choosing an application or library build tool; see vite-8-esbuild-turbopack-webpack-or-tsdown-for-js-builds-2026.

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

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 flagValue / defaultApplies toSource
resolve.aliasMap each import prefix to an absolute directory; first defined rules are applied firstVite 8.3.8shared options
compilerOptions.pathsMatch the same prefix and directory; for example "shared/*": ["./src/app/_shared/*"]TypeScript consumerTS reference
envPrefixDefault VITE_; keep an intentional public prefix, never ''Vite 8.3.8shared options
loadEnv(mode, envDir, prefixes)Defaults to prefix VITE_; '' loads all env regardless of prefix, so never spread that result into client replacementsVite 8.3.8JS API, config
mode (overridden by --mode)Serve defaults to development; build to production; pass actual deployment mode explicitly when differentVite 8.3.8shared options
baseDefault /; /foo/ as an absolute URL pathname, or ./ for embedded deploymentVite 8.3.8shared 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)CauseFixSource
undefinedClient name lacks the public prefixInspect the literal import.meta.env property, selected mode and build inputs; keep secrets server-side and rebuildenv contract
Failed to resolve importCause in this app not established; linked report concerns a historical beta regressionCompare exact import to the absolute alias and TS path; inspect the resolved target before rebuildingalias 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

Subjects

More in documentation

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Vite: repair aliases, public env values and asset paths
Summary: Map aliases to absolute directories, mirror them in TypeScript, and load only intended public values for the selected build mode. Set the deployment asset prefix with `base`
Copy for agent
get the whatworks thread vite-configure-aliases-env-modes-production-base and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread vite-configure-aliases-env-modes-production-base
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks