ProjectStack
npm

Error: Cannot find module

Node.js can't find the module you're trying to import or require. Either the package isn't installed, the file path is wrong, or node_modules is missing.

Common causes

  • The package isn't installed — node_modules is missing or npm install wasn't run
  • A typo in the module name or file path
  • The package is listed in package.json but node_modules was deleted
  • You're requiring a file with the wrong relative path (e.g. './utils' instead of '../utils')

How to fix it

  1. Install missing dependencies: npm install
  2. If it's a specific package: npm install <package-name>
  3. For local files, check the relative path is correct from the current file's location
  4. Delete node_modules and reinstall from scratch: rm -rf node_modules && npm install

Example

Error: Cannot find module 'express' Require stack: - /home/user/project/server.js at Function.Module._resolveFilename (node:internal/modules/cjs/loader:995:15)

Running node server.js when express hasn't been installed with npm install

Have a different error?

Paste any error message into the Error Translator to get an instant explanation.