MODULE_NOT_FOUND

Node.js ErrorCore modulesCommonLast updated: June 28, 2026Tested on:Node.js v20 LTSNPM v10.2June 2026

CommonJS require() failed to resolve a module path.

MODULE_NOT_FOUND Quick Fix⏱️ Est. Fix Time: 3 minutes

Usually happens because:

  • Missing Installation
  • Relative Path Typo
  • Case Sensitivity

🔍 Quick Checklist:

What is MODULE_NOT_FOUND?

The MODULE_NOT_FOUND error occurs when Node.js attempts to resolve a module using the CommonJS require() function, but the module resolution algorithm fails to find the specified npm package, relative file pathway, or local file inside node_modules.

Common Causes

  • Missing Installation: The requested package was never installed (forgot to run 'npm install').
  • Relative Path Typo: Relative paths are typed incorrectly (e.g. require('./utils') but file is named 'util.js').
  • Case Sensitivity: Linux servers are strictly case-sensitive, while Windows dev environments are not.
CauseFrequency
Missing Installation⭐⭐⭐⭐⭐
Relative Path Typo⭐⭐⭐⭐
Case Sensitivity⭐⭐⭐

Common Mistakes

  • Failing to add packages to package.json dependencies, causing deployment server builds to throw MODULE_NOT_FOUND.
  • Mismatching spelling cases (e.g. require('./Helper') works on Windows but throws MODULE_NOT_FOUND on Linux servers).

How to Fix

1Install the Dependency: Run npm install package_name.
2Check File Spelling: Ensure correct relative file extensions and spellings.
3Match Capitalization Cases: Maintain lowercase filenames or ensure capitalization cases match exactly.

Framework-Specific Examples

Wrapping optional configurations requirements inside Express route scripts.

Express Safe Module Require Example
let config;
try {
  config = require('./config.json');
} catch (err) {
  if (err.code === 'MODULE_NOT_FOUND') {
    console.warn('config.json not found, falling back to environment variables.');
    config = process.env;
  }
}

Server Configuration Examples

Checking project build module dependencies before running production deployments.

Static Bundle Checks Config
# Handled by bundlers during compilation

Best Practices

  • Always use git-tracked package.json files.
  • Run npm install before executing code.

Frequently Asked Questions (FAQ)

Q: What causes MODULE_NOT_FOUND?

It is thrown when Node's CJS module loader cannot find the package in `node_modules` or fails to resolve a relative path to a local file.

Q: Why does a module load fine on Windows but fail on Linux with MODULE_NOT_FOUND?

Windows filesystems are case-insensitive. Linux filesystems are strictly case-sensitive. If you write `require('./helpers')` but the file is `Helpers.js`, it will fail on Linux.

Q: How does Node resolve module lookup locations?

Node searches local `node_modules` folders, then walks up parent directories recursively until it reaches root, looking for the target package.

Q: Can I catch MODULE_NOT_FOUND in my script?

Yes. You can wrap `require('...')` statements inside `try-catch` blocks and inspect if `err.code === 'MODULE_NOT_FOUND'`.

Still having this problem?

Didn't solve your problem?

SuggestRequest Error