How do I fix a module not found error in Node.js?

Updated October 2026 · How we answer

Short answerA 'module not found' error in Node.js means the required module cannot be located. Fix it by installing missing dependencies, correcting the path, or checking the module name.

Common Causes

This error typically occurs when you try to require or import a module that isn't installed, or when the path to a local module is incorrect. It can also happen if you're using ES modules and forget the file extension.

Another cause is a mismatch between the module name and the actual package name, such as a typo or case sensitivity issue on case-sensitive file systems.

  • Missing dependency in package.json or node_modules.
  • Incorrect relative path (e.g., './utils' vs '../utils').
  • Forgetting to install dependencies after cloning a repo.
  • Using a core module name that conflicts with a local file.

Solutions

First, run 'npm install' to ensure all dependencies are installed. If the module is not in package.json, install it with 'npm install module-name'. For local modules, double-check the path and file extension.

If you're using ES modules (type: "module" in package.json), you must include the file extension in relative imports. Also, ensure the module name is spelled correctly and matches the package name exactly.

In some cases, clearing the npm cache or deleting node_modules and package-lock.json then reinstalling can resolve corrupted installations.

  • Run 'npm install' to install missing packages.
  • Check relative paths and include file extensions for ES modules.
  • Verify the module name in package.json and node_modules.

Common mistakes

  • Assuming Node.js will automatically install missing modules; it does not.
  • Forgetting that on Linux, file paths are case-sensitive, so 'Require' and 'require' are different.
  • Overlooking that core modules like 'fs' cannot be overridden by local files with the same name.
From our shopsCaseMorph: Type an idea, see a custom phone case in seconds, then print a one-of-one.