Module Not Found: Can't Resolve '@/...' in Next.js - Fixed
Solve the "Module not found: Can't resolve '@/components'" error in Next.js. Step-by-step fix for path aliases and TypeScript configuration.
The Error
Module not found: Can't resolve '@/components/Button'Why This Happens
The @ symbol is a path alias that needs to be configured in your TypeScript/JavaScript config. Next.js uses this for cleaner imports instead of relative paths like '../../../components'.
The Fix
Step 1: Check tsconfig.json
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["./*"]
}
}
}Step 2: Restart Your Dev Server
npm run devStep 3: Verify File Structure
Make sure your import path matches your actual file location:
// If file is at: app/components/Button.tsx
import Button from '@/app/components/Button'
// If file is at: components/Button.tsx
import Button from '@/components/Button'Alternative: Custom Path Aliases
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["./*"],
"@components/*": ["./components/*"],
"@utils/*": ["./utils/*"],
"@lib/*": ["./lib/*"]
}
}
}For JavaScript Projects (jsconfig.json)
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["./*"]
}
}
}Quick Checklist
- Verify tsconfig.json has paths configured
- Restart dev server after config changes
- Check file actually exists at the path
- Ensure import path matches file location
- Check for typos in file names
Frustration Level Before Finding This Fix
How frustrated were you? Vote and see what others experienced!
Related Articles
Hydration Error in Next.js 13/14 - Complete Fix
Fix "Hydration failed because the initial UI does not match what was rendered on the server" error in Next.js with 5 proven solutions.
CORS Error: No Access-Control-Allow-Origin Header - 5 Solutions
Complete guide to fixing CORS errors in your web applications. Learn 5 different approaches from proxy setup to server configuration.
Too Many Re-renders in React - Why & How to Fix
Understanding and fixing "Too many re-renders. React limits the number of renders" error. Learn about common causes and solutions.