node
bundler_error
ai_generated
true
[vite] Pre-transform error: Failed to resolve import "X" from "Y". Does the file exist?
ID: node/vite-dep-prebundle-failed
89%Fix Rate
88%Confidence
60Evidence
2022-01-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 20 | active | — | — | — |
Root Cause
Usually caused by a path alias mismatch between tsconfig.json and vite.config.ts, or missing file extensions in ESM imports. Vite does not read tsconfig paths by default.
genericWorkarounds
-
91% success Install vite-tsconfig-paths plugin or duplicate aliases in vite.config
Vite does not read tsconfig.json paths by default. Either install 'npm install -D vite-tsconfig-paths' and add it to vite plugins array, or manually duplicate your path aliases in vite.config.ts resolve.alias. Example: resolve: { alias: { '@': path.resolve(__dirname, './src') } } -
85% success Add explicit file extensions for ESM imports
Vite in ESM mode may not auto-resolve .ts/.tsx extensions in some configurations. Add the extension explicitly: import { Foo } from './components/Foo.tsx' instead of './components/Foo'. Or configure resolve.extensions in vite.config.ts. -
88% success Check that the imported file actually exists at the resolved path
The error message includes both the import specifier and the importing file. Resolve the path manually relative to the importer. Check for case-sensitivity issues on Linux (macOS is case-insensitive, Linux is not).
Dead Ends
Common approaches that don't work:
-
Adding the import to optimizeDeps.include in vite.config
82% fail
optimizeDeps.include only helps with pre-bundling CJS dependencies into ESM. It does nothing for missing source files, misconfigured path aliases, or wrong import paths. The error is about import resolution, not dependency optimization.
-
Deleting node_modules/.vite and restarting dev server
75% fail
The .vite cache stores pre-bundled dependencies. Clearing it helps when cached deps are corrupted, but when the import path itself is wrong (missing extension, wrong alias), the same error reappears immediately after restart.
Error Chain
Frequently confused with: