Module not found: Can't resolve './components/Header'
Module not found: Can't resolve 'lodash'
This error means your bundler (Webpack, Vite, or Next.js) canβt find a file or package youβre trying to import.
Fix 1: Check the import path
The most common cause β a typo or wrong path:
// β Wrong β case matters on Linux/CI
import Header from './components/header';
// β
Correct
import Header from './components/Header';
Also check:
- File extension (
.tsvs.tsxvs.js) - Relative path (
./for same directory,../for parent) - The file actually exists at that path
Fix 2: Install the missing package
If itβs a package name (not a path), you need to install it:
npm install lodash
Check if itβs in your package.json:
cat package.json | grep lodash
If itβs a dev dependency:
npm install --save-dev @types/lodash
Fix 3: Delete node_modules and reinstall
rm -rf node_modules package-lock.json
npm install
Fix 4: Check TypeScript path aliases
If youβre using path aliases like @/components/..., make sure theyβre configured:
tsconfig.json:
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
}
}
}
Next.js handles this automatically if tsconfig.json is set up. Vite needs vite-tsconfig-paths plugin.
Fix 5: Check file extensions in Next.js App Router
Next.js App Router requires specific file names:
page.tsx(notindex.tsx)layout.tsxloading.tsx
// β Won't work in App Router
app/dashboard/index.tsx
// β
Correct
app/dashboard/page.tsx
Related: Remix: Loader Error β Unexpected Response
Related: shadcn/ui: Component Not Found After Install β How to Fix It