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