πŸ”§ Error Fixes
Β· 1 min read

Vue: Cannot Find Module β€” How to Fix It


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

  1. Wrong file path β€” typo in the import, wrong directory, or missing file extension
  2. Missing .vue extension β€” some configs require it, some don’t
  3. Module not installed β€” the npm package isn’t in node_modules
  4. 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