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
- Read the terminal and the browser console. Vite prints clear errors; the browser shows an error overlay in dev.
- Restart the dev server (
r+ Enter) — config and dependency changes sometimes need it. - Clear the dependency cache:
vite --forcere-runs pre-bundling, or deletenode_modules/.vite. - Reinstall cleanly if things are really odd: delete
node_modulesand reinstall withnpm ci. - Turn on debug logs to see what Vite is doing.
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
[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:
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.
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:
// 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.
node --versionv18.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 thevitetemplate is ideal.
Test yourself
Which flag forces Vite to re-run dependency pre-bundling?
- --clean
- --force
- --reset
- --no-cache
An import works on macOS but fails in the Linux CI build. What's the most likely cause?
- Linux can't run Vite
- A difference in letter case between the import and the file name
- Missing VITE_ prefix
- The port is in use
Edits to files don't trigger updates inside a Docker container. What helps?
build.minify: falseserver.watch.usePolling: truebase: './'optimizeDeps.exclude