Cannot find module
JavaScript Programming Language
Severity: CriticalWhat Does This Error Mean?
Cannot find module means Node.js tried to load a file or package and could not locate it. This is almost always a missing npm install or a typo in the import path. It always appears in the terminal — never in the browser console.
Affected Models
- Chrome DevTools
- Firefox DevTools
- Node.js
- React
- Vue.js
Common Causes
- Running the project without first running npm install
- A typo in the import path or package name
- The package was listed in package.json but not installed (e.g., after a fresh git clone)
- Using a relative path that points to the wrong directory
- Importing a file with the wrong extension (e.g., missing .js or .ts)
How to Fix It
-
Run npm install in your project root directory.
This is the fix for 80% of cases. It downloads all packages listed in package.json into the node_modules folder.
-
Check the import statement for typos.
Package names are case-sensitive. 'Express' is not the same as 'express'. Check the exact name on npmjs.com.
-
Verify the file path for local imports.
Local imports start with ./ or ../. Example: import helpers from './utils/helpers.js' — check that the file exists at that exact path.
-
Delete node_modules and reinstall if install seems corrupted.
Run: rm -rf node_modules && npm install. On Windows use: rmdir /s /q node_modules then npm install.
-
Check your tsconfig.json or webpack config if you use path aliases.
Aliases like @/components only work if your bundler or TypeScript config maps them. A missing mapping causes this error.
When to Call a Professional
If this error appears in a CI/CD pipeline or deployment environment, your DevOps engineer may need to configure the install step. This is not a hardware issue — it is always a configuration or file path problem.
Frequently Asked Questions
Why does this error appear after I clone a project from GitHub?
The node_modules folder is never committed to Git (it is in .gitignore). After cloning, you must run npm install to recreate it. This is standard practice for every Node.js project.
What does the error mean when it says 'Cannot find module path'?
Node is showing you the exact path it searched. Compare that path to where the file actually exists. The difference between the two paths tells you exactly what the typo or misconfiguration is.
Can this happen with a package that is installed?
Yes — if the package name in your import does not exactly match the folder name in node_modules. Also, some packages have a main field misconfigured in their own package.json, causing Node to look in the wrong place.