I was refactoring a component file structure in a Next.js project when every single import broke at once. 43 “Module not found” errors staring at me. Turns out I’d renamed a folder from Components to components on a case-insensitive filesystem. Classic.
The Error
Module not found: Error: Can't resolve './components/Header' in '/Users/dev/my-app/src'
ERROR in ./src/App.js
Module not found: Error: Can't resolve 'react-router-dom' in '/Users/dev/my-app/src'
Or in Next.js:
Module not found: Can't resolve '@/components/Layout'
What it means: Webpack (the bundler behind React, Next.js, and many other frameworks) can’t find a file or package you’re trying to import. The path is wrong, the package isn’t installed, or there’s a casing mismatch.
Why This Happens
This error occurs when:
- The package isn’t installed. You’re importing a library that isn’t in
node_modules - The file path is wrong. Typo in the import path, or the file was moved/renamed
- Case sensitivity mismatch. macOS and Windows are case-insensitive, but Linux (and most CI/CD) is case-sensitive —
Header.js≠header.js - Missing file extension. Some setups require explicit
.js,.jsx, or.tsextensions
The Fix (Tested Solutions)
Solution 1: Install the Missing Package
If the error mentions a package name (not a relative path like ./):
| |
For development dependencies (testing libraries, types, etc.):
| |
💡 After installing, restart your dev server. Webpack doesn’t always pick up new packages automatically.
Solution 2: Fix the Import Path
If the error mentions a relative path (starts with ./ or ../), your file reference is wrong.
Common mistakes:
| |
Quick debugging steps:
- Check the exact filename and folder structure in your file explorer
- Use your IDE’s autocomplete — type
import X from './and let the IDE suggest paths - Check for case sensitivity — this is the #1 hidden cause
Solution 3: Clear Cache and Reinstall
If the import looks correct and the package is installed, your node_modules might be corrupted:
| |
On Windows PowerShell:
| |
Tested On
- ✅ Create React App (v5.x)
- ✅ Next.js 14 / 15
- ✅ Vite + React
- ✅ Webpack 5
- ✅ Windows, macOS, Ubuntu
Prevention
- Use your IDE’s auto-import feature — let it generate the import path for you
- Don’t rename files outside your IDE — file explorers don’t update imports
- Keep a consistent naming convention — all lowercase with hyphens is safest
- Run
npm installafter pulling changes from Git — someone on your team may have added new dependencies
FAQ
Q: Why does this work locally but fail in CI/CD?
A: Almost certainly a case sensitivity issue. Your local machine (macOS/Windows) ignores Header vs header, but Linux CI servers don’t. Fix the casing to match exactly.
Q: I installed the package but still get the error. Why?
A: Try deleting node_modules and running npm install fresh. Also check if you installed it in the right directory — make sure you’re not in a parent folder.
Q: Does this error affect production or just development? A: It blocks the build entirely. Your app won’t compile until every import resolves correctly.
Last verified: February 14, 2026