TExcelTAD
Home › Vite › Vite Troubleshooting

Vite Troubleshooting

Vite is usually smooth, but a few problems come up again and again. This lesson collects the most common symptoms, what causes them, and how to fix them.

First steps for any problem

  1. Read the terminal and the browser console. Vite prints clear errors; the browser shows an error overlay in dev.
  2. Restart the dev server (r + Enter) — config and dependency changes sometimes need it.
  3. Clear the dependency cache: vite --force re-runs pre-bundling, or delete node_modules/.vite.
  4. Reinstall cleanly if things are really odd: delete node_modules and reinstall with npm ci.
  5. Turn on debug logs to see what Vite is doing.
bash · try it yourself
npx vite --force --debug deps
  vite:deps scanning for dependencies... +0ms
  vite:deps dependencies found by scanner: vue, pinia +142ms
  vite:deps creating new cache +3ms
  vite:deps ✨ dependencies optimized +318ms

  VITE v8.3.4  ready in 541 ms

  ➜  Local:   http://localhost:5173/
  ➜  Network: use --host to expose
  ➜  press h + enter to show help

Symptom → cause → fix

Symptom Likely cause Fix
Port 5173 is in use, trying another one... Another dev server is running Stop it, or set server.port / strictPort: true
Saving files does nothing File watcher events lost (Docker, WSL2, network drive) server.watch.usePolling: true
Blank page after deploy, 404 on /assets/*.js Wrong base Set base to the deployed sub-path
Refreshing /about gives 404 in production No SPA fallback on host try_files ... /index.html or host rewrite rules
import.meta.env.MY_VAR is undefined Missing VITE_ prefix, or env file in wrong folder Rename to VITE_MY_VAR, put .env in the project root, restart
Failed to resolve import "@/x" Alias not configured Add resolve.alias (and tsconfig paths)
The requested module does not provide an export named 'default' CommonJS package interop Use a named import, add it to optimizeDeps.include, or switch to an ESM package
Page reloads repeatedly on first visit Dependencies discovered late → re-optimization Add them to optimizeDeps.include
[vite] Internal server error: Preprocessor dependency "sass-embedded" not found Compiler not installed npm i -D sass-embedded
Type errors in editor but build succeeds Vite doesn't type-check Run tsc --noEmit / vue-tsc in CI
process is not defined in the browser Code (often from a Node-oriented package) reads process.env Use import.meta.env, or define: { 'process.env.NODE_ENV': '"production"' }
HMR does a full reload for every edit Module isn't accepted by any HMR boundary Framework plugin missing, or file exports non-components (React)

Reading a resolve error

text
[plugin:vite:import-analysis] Failed to resolve import "./componets/Header.vue" from "src/App.vue". Does the file exist?
/home/me/app/src/App.vue:3:20
1  |  <script setup>
2  |  import { ref } from 'vue'
3  |  import Header from './componets/Header.vue'
   |                     ^

The message tells you which plugin failed, what it tried to import, from where, and points at the line. Here it is a typo (componets). A quick script can even suggest the closest existing path:

js · try it yourself
function distance(a, b) {
  const dp = Array.from({ length: a.length + 1 }, (_, i) => [i, ...Array(b.length).fill(0)]);
  for (let j = 1; j <= b.length; j++) dp[0][j] = j;
  for (let i = 1; i <= a.length; i++)
    for (let j = 1; j <= b.length; j++)
      dp[i][j] = Math.min(dp[i - 1][j] + 1, dp[i][j - 1] + 1, dp[i - 1][j - 1] + (a[i - 1] === b[j - 1] ? 0 : 1));
  return dp[a.length][b.length];
}

const existing = ['./components/Header.vue', './components/Footer.vue', './composables/useAuth.js'];
const wanted = './componets/Header.vue';
const best = existing.map((p) => ({ p, d: distance(wanted, p) })).sort((x, y) => x.d - y.d)[0];
console.log(`Failed to resolve "${wanted}". Did you mean "${best.p}"? (distance ${best.d})`);
Failed to resolve "./componets/Header.vue". Did you mean "./components/Header.vue"? (distance 1)

Case sensitivity

macOS and Windows file systems are usually case-insensitive; Linux (your CI server, your Docker image) is not. import Header from './header.vue' works locally but fails in CI when the file is Header.vue. Always match the exact case.

js · try it yourself
const filesOnLinux = new Set(['src/components/Header.vue']);
const imports = ['src/components/Header.vue', 'src/components/header.vue'];

for (const p of imports) {
  const linux = filesOnLinux.has(p);
  const mac = [...filesOnLinux].some((f) => f.toLowerCase() === p.toLowerCase());
  console.log(p.padEnd(26), `mac/win: ${mac ? 'ok' : 'missing'}`, `| linux: ${linux ? 'ok' : 'missing'}`);
}
src/components/Header.vue  mac/win: ok | linux: ok
src/components/header.vue  mac/win: ok | linux: missing

CommonJS interop

Some older packages only ship CommonJS. Vite converts them during pre-bundling, but edge cases happen, especially with packages that are linked locally (monorepos) and therefore not pre-bundled:

js
// vite.config.js
export default defineConfig({
  optimizeDeps: {
    include: ['legacy-cjs-lib', 'my-linked-package > some-cjs-dep'],
  },
});

Network / host issues

Problem Fix
Can't open the dev server from another device vite --host and allow the port in your firewall
"Blocked request. This host is not allowed." Add the hostname to server.allowedHosts (e.g. a tunnel domain)
HMR WebSocket fails behind a reverse proxy Configure server.hmr.clientPort / server.hmr.host to the public values
CORS errors calling your API Use server.proxy in dev instead of calling another origin

Node version

Vite 8 needs Node.js 20.19+ or 22.12+. Older versions fail with confusing syntax or require(esm) errors.

bash · try it yourself
node --version
v18.20.4

That one is too old — upgrade Node (for example with nvm install 22) and reinstall dependencies.

Tip: When you ask for help (GitHub issue, forum, colleague), include the Vite version (npx vite --version), Node version, OS, the full error, and a minimal reproduction — StackBlitz with the vite template is ideal.

Test yourself

Which flag forces Vite to re-run dependency pre-bundling?

  1. --clean
  2. --force
  3. --reset
  4. --no-cache

An import works on macOS but fails in the Linux CI build. What's the most likely cause?

  1. Linux can't run Vite
  2. A difference in letter case between the import and the file name
  3. Missing VITE_ prefix
  4. The port is in use

Edits to files don't trigger updates inside a Docker container. What helps?

  1. build.minify: false
  2. server.watch.usePolling: true
  3. base: './'
  4. optimizeDeps.exclude