npm install failures can halt development. This guide covers all common npm errors and their solutions.
Error: ERESOLVE - Dependency Conflict
Symptom:
npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR! While resolving: some-package@1.0.0
npm ERR! Found: react@18.2.0
npm ERR! Could not resolve dependency:
npm ERR! peer react@"^17.0.0" from another-package@2.0.0
Solution 1 - Force install (quick fix):
# Skip peer dependency checks
npm install --legacy-peer-deps
# Or force through conflicts
npm install --forceSolution 2 - Use overrides (package.json):
{
"overrides": {
"react": "^18.2.0",
"react-dom": "^18.2.0"
}
}Solution 3 - Update conflicting packages:
# Find outdated packages
npm outdated
# Update specific package
npm update another-package
# Check for newer compatible versions
npm view another-package versionsError: EACCES - Permission Denied
Symptom:
npm ERR! code EACCES
npm ERR! syscall access
npm ERR! path /usr/local/lib/node_modules
npm ERR! Error: EACCES: permission denied
Solution 1 - Fix npm prefix (recommended):
# Create npm global directory in home folder
mkdir -p ~/.npm-global
npm config set prefix '~/.npm-global'
# Add to PATH (~/.bashrc or ~/.zshrc)
export PATH=~/.npm-global/bin:$PATH
# Reload shell
source ~/.bashrcSolution 2 - Fix ownership:
# Fix npm cache permissions
sudo chown -R $(whoami) ~/.npm
# Fix node_modules permissions
sudo chown -R $(whoami) /usr/local/lib/node_modulesSolution 3 - Use nvm (best solution):
# Install nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
# Install Node via nvm (no sudo needed)
nvm install 20
nvm use 20Error: ENOENT - File Not Found
Symptom:
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path /project/package.json
npm ERR! enoent ENOENT: no such file or directory
Solution 1 - Verify you're in correct directory:
# Check current directory
pwd
# Check if package.json exists
ls -la package.json
# Initialize if missing
npm init -ySolution 2 - Clear cache and reinstall:
# Clear npm cache
npm cache clean --force
# Delete node_modules and lock file
rm -rf node_modules package-lock.json
# Reinstall
npm installSolution 3 - Fix corrupted package-lock.json:
# Remove and regenerate lock file
rm package-lock.json
npm install
# Or use npm ci for CI environments
npm ciError: node-gyp Build Failed
Symptom:
npm ERR! code 1
npm ERR! gyp ERR! build error
npm ERR! node-gyp rebuild
npm ERR! gyp: No Xcode or CLT version detected!
Solution 1 - Install build tools (macOS):
# Install Xcode Command Line Tools
xcode-select --installSolution 2 - Install build tools (Windows):
# Run PowerShell as Administrator
npm install --global windows-build-tools
# Or install Visual Studio Build Tools manually
# https://visualstudio.microsoft.com/visual-cpp-build-tools/Solution 3 - Install build tools (Linux):
# Ubuntu/Debian
sudo apt-get install build-essential python3
# CentOS/RHEL
sudo yum groupinstall "Development Tools"
sudo yum install python3Solution 4 - Specify Python version:
# If multiple Python versions installed
npm config set python /usr/bin/python3
# Or set per-project
npm install --python=/usr/bin/python3Error: Network / Registry Issues
Symptom:
npm ERR! code ETIMEDOUT
npm ERR! network request to https://registry.npmjs.org/ failed
npm ERR! code ECONNRESET
npm ERR! network socket hang up
Solution 1 - Use different registry:
# Use npm mirror
npm config set registry https://registry.npmmirror.com
# Reset to default
npm config set registry https://registry.npmjs.org
# Check current registry
npm config get registrySolution 2 - Configure proxy:
# HTTP proxy
npm config set proxy http://proxy.company.com:8080
npm config set https-proxy http://proxy.company.com:8080
# Remove proxy
npm config delete proxy
npm config delete https-proxySolution 3 - Increase timeout:
npm config set fetch-timeout 60000
npm config set fetch-retries 5Error: EINTEGRITY - Checksum Mismatch
Symptom:
npm ERR! code EINTEGRITY
npm ERR! sha512-xxxx integrity checksum failed
npm ERR! Verification failed while extracting package
Solution 1 - Clear cache and reinstall:
# Clear cache
npm cache clean --force
# Delete lock file and node_modules
rm -rf node_modules package-lock.json
# Reinstall
npm installSolution 2 - Verify npm registry:
# Check if registry is correct
npm config get registry
# Reset registry
npm config set registry https://registry.npmjs.orgError: Maximum Call Stack Size Exceeded
Symptom:
npm ERR! Maximum call stack size exceeded
RangeError: Maximum call stack size exceeded
Solution - Clear and reinstall:
# Full cleanup
rm -rf node_modules package-lock.json ~/.npm/_cacache
# Update npm
npm install -g npm@latest
# Install with clean cache
npm cache clean --force
npm installError: Unsupported Engine
Symptom:
npm WARN EBADENGINE Unsupported engine
npm WARN EBADENGINE current: { node: '16.0.0', npm: '8.0.0' }
npm WARN EBADENGINE required: { node: '>=18.0.0' }
Solution 1 - Update Node.js:
# Using nvm
nvm install 20
nvm use 20
# Verify version
node --versionSolution 2 - Ignore engine check (temporary):
npm install --ignore-enginesSolution 3 - Set engines in package.json:
{
"engines": {
"node": ">=18.0.0",
"npm": ">=9.0.0"
}
}Error: Cannot Find Module
Symptom:
Error: Cannot find module 'some-package'
MODULE_NOT_FOUND
Solution 1 - Reinstall dependencies:
rm -rf node_modules
npm installSolution 2 - Check installation:
# Verify package is installed
npm ls some-package
# Install missing package
npm install some-packageSolution 3 - Check import path:
// ❌ Wrong import
import something from 'Some-Package'; // Case matters!
// ✅ Correct import
import something from 'some-package';npm vs yarn vs pnpm
| Issue | npm | yarn | pnpm |
|-------|-----|------|------|
| Peer deps | --legacy-peer-deps | --ignore-peer-deps | --ignore-peer-deps |
| Clean install | npm ci | yarn install --frozen-lockfile | pnpm install --frozen-lockfile |
| Cache clean | npm cache clean --force | yarn cache clean | pnpm store prune |
| Global path fix | Set prefix | Set prefix | Set global-bin-dir |
Quick Debug Checklist
# 1. Check Node/npm version
node --version
npm --version
# 2. Check npm config
npm config list
# 3. Clear everything
npm cache clean --force
rm -rf node_modules package-lock.json
# 4. Reinstall
npm install
# 5. Verbose output if still failing
npm install --verbose 2>&1 | tee npm-debug.logComplex npm Issues?
Package management at scale requires careful dependency management. Our team can help with:
- Monorepo setup and optimization
- Private registry configuration
- Build performance optimization
- Security vulnerability remediation