Module not found: Error: Can't resolve 'module-name'
Educational use only. Content explains errors and defensive fixes for systems you own or are authorised to test. Do not use any technique here to access data, accounts, or networks without permission.
Root Cause
This error indicates that Node.js or your module bundler (Webpack, Rollup, etc.) cannot locate the package or file you are trying to import. The most common causes are a simple typo in the package name or file path, forgetting to run `npm install` after pulling new code, or a missing file extension in your import statement. It can also occur if you are importing a local file using a relative path, but the path is incorrect relative to the current file's location.
Fix / Solution
First, verify that the module is listed in your `package.json` and that you have run `npm install`. Double-check the spelling of the import statement. For local files, ensure the relative path is correct (e.g., `../components/Button` instead of `./components/Button`). If using TypeScript or specific bundlers, check if your configuration requires explicit file extensions for certain file types.
Code Snippet
// ❌ Typo or missing dependency
import { SomeComponent } from 'react-domm';
// ❌ Incorrect relative path
import utils from './utils'; // When utils is in parent directory
// ✅ Correct path and dependency
import { SomeComponent } from 'react-dom';
import utils from '../utils';