What this error means
Error [ERR_MODULE_NOT_FOUND] means npm or Node.js cannot resolve the project files, package metadata, dependency graph, or module path required by the command. Check the project root, lockfile, and Node version first.
Why this happens
Node projects depend on a consistent relationship between package.json, lockfiles, installed modules, and runtime version.
For Node.js ERR_MODULE_NOT_FOUND, local success can be misleading if node_modules is stale or the lockfile was not regenerated.
Common causes
- Relative import is missing a file extension
- Package is not installed
- Path points to a CommonJS-only entry incorrectly
- Case-sensitive filesystem reveals a path mismatch
Quick fixes
- Run the command from the folder containing
package.json. - Check the exact import specifier, include required file extensions for relative ESM imports, and reinstall dependencies.
- Check
node --versionandnpm --version. - Use
npm cifor a clean lockfile-based install when a lockfile exists.
Copy-paste commands
Check runtime versions
node --version
npm --version
Install dependencies
npm install
Clean CI-style install
npm ci
Clear npm cache
npm cache clean --force
Reset local install state
rm -rf node_modules package-lock.json
npm install
Platform-specific fixes
CI/CD
- Prefer
npm ciin CI so the build fails whenpackage.jsonandpackage-lock.jsondrift apart.
Real-world fixes
- If the error names a peer dependency, update the plugin and framework versions together.
- If the error names a missing file, check filename casing; CI often runs on a case-sensitive filesystem.
- Check the exact import specifier, include required file extensions for relative ESM imports, and reinstall dependencies.
Step-by-step troubleshooting
- Find the first
Error [ERR_MODULE_NOT_FOUND]occurrence in the npm output; later stack lines are often symptoms. - Confirm the command is running in the intended package directory.
- Compare
package.jsonandpackage-lock.jsonafter dependency changes. - Remove stale
node_modulesonly after checking whether the lockfile is committed. - Rerun the failing command with the same Node version used in CI or production.
How to prevent it
- Commit lockfile changes with dependency changes.
- Pin the project Node version in
.nvmrc,.node-version, or CI configuration. - Use CI to catch dependency drift before deploy.