MODULE_NOT_FOUND in Node.js — What It Means and How to Fix It

What the Node.js/npm error MODULE_NOT_FOUND means and how to resolve it.

Published October 25, 2026

'Cannot find module' means Node could not resolve a required or imported package or file.

What it means and why it happens

Typical causes: dependencies not installed, wrong relative path, a typo, or package not listed in package.json.

Read the full message: it names the file and line where the problem was detected, which is the best place to start.

What you see

run the code
Error: Cannot find module 'express'

Practical examples

Code that triggers it

const express = require('express')   // not installed

The fix

npm install express
const express = require('express')

Diagnose

npm ls express
rm -rf node_modules package-lock.json && npm install

Common mistakes

  • Forgetting npm install after cloning.
  • Case-sensitive paths.
  • Missing file extensions in ES modules.

Key takeaways

  • Module not found: 'Cannot find module' means Node could not resolve a required or imported package or file.
  • Read the message and the line number first.
  • Fix the cause, don't just silence the error.

FAQ

Relative imports?

Use ./ and include .js in ESM imports.

How do I find which line caused Module not found?

The error message and stack trace show the file and line; start there and work backwards.

More JavaScript articles