Skip to content
Module not found: Error: Can't resolve '...'

Module not found: Error: Can't resolve '...'

DodaTech 3 min read

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.extensions doesn’t include it.
  • A resolve.alias in 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 axios

2. Check the import path and file extension

Verify the file exists at the exact path:

ls src/components/Button.jsx

Fix 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.jsx

4. Clean and rebuild

rm -rf node_modules package-lock.json
npm install
npm run build

5. 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';
Does this error mean my code is broken?
Not necessarily — it means webpack can’t find the file at build time. The source code structure or import path needs adjustment. Check the exact module name in the error and the file that triggered it, printed above the error message.
Why does webpack work on Windows but fail on Linux?
Windows has case-insensitive file paths, while Linux and macOS (with default APFS) are case-sensitive. An import like import Button from './components/Button' when the file is actually ./Components/Button will work on Windows but fail on Linux. Always use the exact case in import paths regardless of your OS.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro