[vite] Internal server error: Failed to resolve import. Does the file exist?
#168Error
[plugin:vite:import-analysis] Failed to resolve import "@/components/Button" from "src/App.tsx". Does the file exist?
Why it happens, and why this works
Vite couldn't find the import. Most often a path alias like @/ is set in tsconfig.json paths but not in Vite (TypeScript paths only affect type checking, not bundling), or the file name's case differs, or the package isn't installed.
Fix
1. Add the alias to vite.config: resolve: { alias: { "@": path.resolve(__dirname, "./src") } } (or use the vite-tsconfig-paths plugin).
2. Check exact filename case: Button.tsx vs button.tsx works on Windows/macOS but fails on Linux and in CI.
3. For a package, npm install it and restart the dev server.
4. Delete node_modules/.vite and restart if it just started after a dependency change.Did it work?
No reports yetRelated fixes
ImportError: cannot import name from partially initialized module (circular import)
#52ImportError: cannot import name 'User' from partially initialized module 'models' (most likely due to a circular import). Python 3.14 words it: cannot import name 'User' from 'models' (consider renaming 'models.py' if it has the same name as a library you intended to import)
node --test can't import project files: Cannot use import statement outside a module
#7SyntaxError: Cannot use import statement outside a module (or ERR_REQUIRE_ESM) when running node --test against lib/*.js files that use import/export.
ENOENT reading a file that exists: relative path resolved from the wrong folder
#30Error: ENOENT: no such file or directory, open './data.json' (the file is right next to the script)