Cannot find module './components/MyComponent.vue' or Module not found: Error: Can't resolve in Vue.js means the import path doesnβt match an actual file.
What causes this error
- Wrong file path β typo in the import, wrong directory, or missing file extension
- Missing
.vueextension β some configs require it, some donβt - Module not installed β the npm package isnβt in
node_modules - TypeScript canβt find Vue files β missing type declaration
Fix 1: Check the file path
// β Common mistakes
import MyComponent from './components/myComponent' // wrong case
import MyComponent from './component/MyComponent.vue' // wrong folder name
import MyComponent from '../MyComponent.vue' // wrong relative path
// β
Exact match required
import MyComponent from './components/MyComponent.vue'
Vue file imports are case-sensitive on Linux/Mac. MyComponent β myComponent.
Fix 2: Add Vue type declaration for TypeScript
Create src/env.d.ts or src/shims-vue.d.ts:
declare module '*.vue' {
import type { DefineComponent } from 'vue'
const component: DefineComponent<{}, {}, any>
export default component
}
Fix 3: Install missing packages
# Check if the package exists
ls node_modules/package-name
# If not, install it
npm install package-name
Fix 4: Clear cache and reinstall
rm -rf node_modules package-lock.json
npm install
Sometimes the module exists but the cache is stale. A clean install fixes it.
Related: Vue.js cheat sheet Β· TypeScript: Cannot Find Module Β· Vite: Failed to Resolve Import