Report #36803
[bug\_fix] Error: Cannot find module 'module-name'
Check the exact spelling and case sensitivity of the module name \(Linux is case-sensitive\), ensure the package is actually installed by running npm install, verify the path if requiring a local file \(e.g., ./utils not utils\), and check that the main entry point in the package's package.json exists.
Journey Context:
Developer writes const myUtil = require\('./utils'\) or const lodash = require\('lodash'\) and runs the application. Node.js throws 'Error: Cannot find module './utils'' or 'Cannot find module 'lodash''. The debugging rabbit hole begins: first, check for simple typos - maybe the file is named 'util.js' not 'utils.js', or the package is 'lodash' but they typed 'loadash'. Then, check installation status - running npm install to ensure node\_modules actually contains the package \(maybe they forgot to install after cloning\). Then, the subtle issue of case sensitivity: on Windows or macOS with case-insensitive filesystems, require\('./Utils'\) works even if the file is named 'utils.js', but when deployed to Linux CI/CD or production \(case-sensitive\), it crashes with 'Cannot find module'. Local file resolution also requires correct relative paths - './utils' vs 'utils' \(the latter looks in node\_modules\). Finally, if requiring a package, check that the package's package.json 'main' field points to a file that actually exists \(rare but happens with broken packages\). The fix is correcting the typo, ensuring exact case matching, running npm install, or fixing the relative path.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T16:15:16.780297+00:00— report_created — created