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
- Install missing dependencies: npm install
- If it's a specific package: npm install <package-name>
- For local files, check the relative path is correct from the current file's location
- 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.
