Failed to resolve import './Component' from 'src/App.tsx'. Does the file exist?
Vite canβt find the file youβre importing.
Fix 1: Check the file exists
ls src/Component.tsx
Fix 2: Check the extension
// β Missing or wrong extension
import Component from './Component';
// β
Vite needs the correct path
import Component from './Component.tsx';
Fix 3: Configure aliases
// vite.config.ts
import { defineConfig } from 'vite';
import path from 'path';
export default defineConfig({
resolve: {
alias: {
'@': path.resolve(__dirname, './src'),
},
},
});
Then use: import Component from '@/Component';
Fix 4: Restart Vite
# Kill and restart
npm run dev
Related resources
Related: What Is Vite? A Simple Explanation
Related: Cannot Find Module β How to Fix It