Cannot Find Module '[module-name]' — Node.js Module Not Found Fix
This error matches known, documented patterns with reliable solutions.
Quick Fix (Most Common Solution)
- Run npm install in the project root directory to install all dependencies
- If a specific package is named in the error, install it directly: npm install [package-name]
Seeing "Error: Cannot find module"? This error can be frustrating, but it's usually fixable. It typically affects your development workflow or system. Below you'll find clear, step-by-step solutions to resolve this issue.
What This Error Means
Node.js could not locate the required module. Either the package is not installed in node_modules, or a relative file path import has a typo. This is one of the most common Node.js errors after cloning a repository.
Frequently documented in developer and vendor support forums.
Not affiliated with browser, OS, or device manufacturers.
New here? Learn why exact error messages matter →
Common Causes
- Package is not installed — missing from node_modules
- node_modules was deleted and npm install was not rerun after the deletion
- Package listed in package.json but npm install was not run after pulling from git
- Relative path import has a typo or incorrect directory depth (e.g. ../utils instead of ./utils)
How to Fix
- Run npm install in the project root directory to install all dependencies
- If a specific package is named in the error, install it directly: npm install [package-name]
- If node_modules exists but the error persists, delete it and reinstall cleanly
- If the error names a local file path, verify the file exists with the exact capitalisation shown in the import
Last reviewed: June 2026 How we review solutions
Didn't fix it? Get a personalised solution
Environment-Specific Commands
Install missing dependencies
npm installnpm install [package-name]
Full reset if install does not fix it
rm -rf node_modulesrm package-lock.jsonnpm install
Windows (PowerShell)
Remove-Item -Recurse -Force node_modulesRemove-Item package-lock.jsonnpm install
Quick Diagnostic Path
- If Error names a package like 'react' or 'express' → Run: npm install [package-name] then rerun the application
- If Error names a relative path like './utils/helper' → The file does not exist at that path. Check for typos and case sensitivity.
- If Error says MODULE_NOT_FOUND but package is in package.json → node_modules is missing or corrupt — run: rm -rf node_modules && npm install
If This Still Fails, Check
- Monorepos: running npm install from a workspace subdirectory may not install all dependencies — run it from the repository root
- TypeScript projects: Cannot find module can mean a missing @types package — install: npm install -D @types/[package-name]
- Docker containers: if you copy node_modules into the image but run on a different OS, native modules may be incompatible — run npm install inside the container
Debug and fix Cannot find module
# Step 1: install all dependencies
npm install
# Step 2: install a specific missing package
npm install [package-name]
# Step 3: full reset if above does not fix it
rm -rf node_modules package-lock.json
npm install
# Step 4: verify the module loads
node -e "require('[package-name]')" && echo "Module found OK"CI/CD Considerations
Cannot Find Module in Node.js CI: Build vs Runtime Environment Gaps
Cannot Find Module that appears only in CI or only in production usually traces to a gap between the build environment and the runtime environment. Node.js applications built on one Node version and run on another frequently encounter this class of error.
The standard preventive: pin Node version in both the build pipeline and the runtime image using the same identifier — for example, node:20.11.0-alpine rather than node:20-alpine. The minor version matters because V8 updates within minor releases can affect runtime behavior. For TypeScript projects, the compiled JavaScript must target the runtime Node version's supported JavaScript features — check tsconfig.json's target and lib settings. Native modules (compiled with node-gyp) must be compiled for the runtime architecture and Node version, not the build machine's — use npm rebuild in the runtime Dockerfile stage after copying node_modules. Environment variables available during npm run build (like NODE_ENV) affect bundling behavior and may produce different output than expected in production.Optional follow-up
Some users ask whether saving fixes for recurring errors would be useful when the same issue appears again.
Was this explanation helpful?
Frequently Asked Questions
Why does this happen after git clone?
node_modules is excluded by .gitignore and is not committed to git. After cloning, run npm install to create node_modules from package.json.
The module is installed but the error still happens
Check case sensitivity: on Linux, MyFile.js and myfile.js are different files. The import path must match the filename exactly, including capitalisation.
Cannot find module with a relative path like './utils'
The file at that path does not exist or the path is wrong. Verify with: ls ./utils/ from the directory containing the import.
Related Resources
Also Known As
- Node.js error
- Node runtime error
- JavaScript server error
- Node exception
Common Search Variations
- "node js error fix"
- "node command not working"
- "node app crashing"
- "javascript server error solution"
- "node runtime crash fix"
- "how to debug node error"
Related Errors
Still Stuck?
Paste a different error message or upload a screenshot to get help instantly.