Module not found: Error: Can't resolve '...'
Module not found: Error: Can't resolve means webpack cannot find an imported module. Fix it by installing the package, fixing the path, or updating webpack config.
What It Means
webpack walks your import graph starting from the entry point. For each import or require, it resolves the module path using its own resolution algorithm (similar to Node.js but configurable via resolve in webpack.config.js). When a module can’t be found at any of the resolved paths, webpack throws this error with the exact module name and the file that imported it.
Why It Happens
- The imported package is not installed in
node_modules. - The import path is incorrect — case-sensitivity matters on Linux and macOS.
- The file extension is missing and webpack’s
resolve.extensionsdoesn’t include it. - A
resolve.aliasin the webpack config points to a non-existent directory. - The module uses a subpath that isn’t exported in the package’s
package.json"exports"field. - The package exists but is not included in the webpack bundle scope (e.g., outside
src/).
How to Fix It
1. Install the missing package
npm install <package-name>For example, if the error is Can't resolve 'axios':
npm install axios2. Check the import path and file extension
Verify the file exists at the exact path:
ls src/components/Button.jsxFix the import:
// Wrong casing — will fail on Linux
import Button from './Components/Button';
// Correct casing
import Button from './components/Button';Add missing extensions configured in webpack:
import data from './data'; // if resolve.extensions includes '.json'
3. Check webpack resolve configuration
// webpack.config.js
module.exports = {
resolve: {
extensions: ['.js', '.jsx', '.ts', '.tsx', '.json'],
alias: {
'@': path.resolve(__dirname, 'src/')
}
}
};If you use an alias like @/components/Button, make sure the alias path exists:
ls src/components/Button.jsx4. Clean and rebuild
rm -rf node_modules package-lock.json
npm install
npm run build5. Check package exports field
Some modern packages restrict which subpaths can be imported:
// May fail if package.json has "exports" that limits subpaths
import something from 'package/dist/something';
// Use the main export instead
import something from 'package';Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro