This error occurs when Node.js cannot find a required module because dependencies haven't been installed. Run npm install to download all dependencies listed in package.json.
This error occurs when Node.js attempts to load a module (dependency) that doesn't exist in your project's node_modules directory. It typically appears when you try to run a script or import a package before dependencies are installed, or when the node_modules directory becomes corrupted or incomplete. The error indicates that your project has a package.json file defining required dependencies, but those dependencies haven't been installed yet or have been lost. The error can manifest when running npm scripts, importing third-party packages, or when node_modules was deleted or corrupted.
The most straightforward fix is to install all dependencies listed in your package.json file:
npm installThis command reads your package.json and package-lock.json files and downloads all required dependencies into the node_modules directory.
If a simple npm install doesn't resolve the issue, the node_modules directory may be corrupted:
On macOS/Linux:
rm -rf node_modules
rm -f package-lock.json
npm installOn Windows (PowerShell):
Remove-Item -Recurse -Force node_modules
Remove-Item package-lock.json
npm installnpm maintains a cache that can become corrupted. Clear it and perform a complete reinstall:
npm cache clean --force
rm -rf node_modules
rm -f package-lock.json
npm installThe --force flag bypasses safety checks in case the cache is severely corrupted.
Check that the missing module is actually listed in your package.json:
{
"dependencies": {
"express": "^4.18.0",
"lodash": "^4.17.21"
},
"devDependencies": {
"jest": "^29.0.0"
}
}If the package is missing from package.json, install it explicitly:
npm install package-name --saveFor development dependencies:
npm install package-name --save-devIn some cases, npm fails to install dependencies due to peer dependency conflicts:
npm install --legacy-peer-depsThis should only be used as a temporary workaround. Ideally, update your packages to compatible versions.
Version mismatches between Node.js and npm can cause installation issues:
node --version
npm --versionIf you've recently updated Node.js, perform a fresh reinstall:
rm -rf node_modules package-lock.json
npm cache clean --force
npm installAfter installing dependencies, restart any running development servers:
# Stop your current process (Ctrl+C)
# Then restart your server
npm startIf standard troubleshooting doesn't work, use diagnostic commands: npm list shows all installed packages and warns about missing dependencies. For specific packages, npm list package-name verifies installation location. In monorepo setups using npm workspaces, ensure you run npm install from the root directory. For CI/CD pipelines, use npm ci (clean install) instead of npm install for reproducible builds with exact package-lock.json versions. On Windows with antivirus software, file access restrictions can interrupt installations—temporarily disable antivirus or add node_modules to exclusion lists.
npm ERR! code E401 npm ERR! 401 Unauthorized - Token has expired
Token has expired - npm authentication failure
npm ERR! code EAI_NODATA npm ERR! errno EAI_NODATA npm ERR! getaddrinfo EAI_NODATA registry.npmjs.org
How to fix "npm ERR! code EAI_NODATA - getaddrinfo EAI_NODATA"
npm ERR! code EMPTYPACKAGE npm ERR! Package contains no files
How to fix 'npm ERR! code EMPTYPACKAGE' - Package contains no files
npm ERR! code EWORKSPACEMISSING npm ERR! Workspace does not exist: packages/missing
How to fix "npm ERR! code EWORKSPACEMISSING - Workspace does not exist" error
npm ERR! code EADDRNOTAVAIL npm ERR! errno EADDRNOTAVAIL npm ERR! Address not available
How to fix "npm ERR! code EADDRNOTAVAIL - Address not available" error