Skip to content
Troubleshooting⏱️ 11 min read·

How to Fix npm Install Errors (ERESOLVE, EACCES) and Manage Node.js Versions with NVM

Solve dependency tree conflicts (ERESOLVE unable to resolve dependency tree), permission errors (EACCES), and seamlessly switch Node versions on macOS, Linux, and Windows using NVM.

MN
Manoj NeupaneSoftware Developer & Programming Instructor
#npm#Node.js#NVM#JavaScript#DevOps
🎯 Who This Tutorial Is For

Developers facing npm install crashes when cloning existing repositories or upgrading packages.

📋 Prerequisites
  • ✓Terminal access on macOS, Linux, or Windows

🚀 What You Will Learn & Build

  • ▸Resolving 'ERESOLVE unable to resolve dependency tree'
  • ▸When to use --legacy-peer-deps safely
  • ▸Fixing EACCES permission errors without using sudo npm
  • ▸Installing and managing multiple Node.js versions with NVM
1

1. Fixing 'ERESOLVE unable to resolve dependency tree'

In npm v7+, npm strictly verifies peer dependencies. If library A requires React 17 while library B requires React 18, npm halts installation with `ERESOLVE`. **Solution 1: Use --legacy-peer-deps** ```bash npm install --legacy-peer-deps ``` This tells npm to ignore conflicting peer dependencies (reverting to npm v6 behavior). **Solution 2: Clean node_modules and reinstall** ```bash rm -rf node_modules package-lock.json npm cache clean --force npm install --legacy-peer-deps ```
2

2. Managing Node.js Versions with NVM (Node Version Manager)

Different projects require different Node.js versions (e.g. an older app needs Node 16, while Next.js 14 requires Node 18+). Never install Node directly from nodejs.org installers. Use **NVM**:
Terminal
# Install NVM on macOS / Linux:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash

# Restart your terminal, then:
# Install Node.js LTS v20
nvm install 20

# Install Node.js v18
nvm install 18

# Switch between versions instantly
nvm use 20

# Set default Node version
nvm alias default 20

✨ Expected Output & Verification

npm install completes with "added X packages in Ys" with 0 audit vulnerabilities.

🧪 How to Test the Implementation

  1. 1Run `node -v` to ensure you are running the expected runtime
  2. 2Run `npm test` or `npm run dev` to verify clean startup

⚠️ Common Errors & How to Fix Them

❌npm ERR! Error: EACCES: permission denied

Root Cause: Installing packages with 'sudo npm', which corrupts ownership of ~/.npm folder.

Fix: Fix ownership: sudo chown -R $(whoami) ~/.npm. Never use sudo with npm install -g; use NVM instead.

🛡️ Security Considerations & Best Practices

  • !Review npm audit output before pushing dependencies to production.

❓ Frequently Asked Questions (FAQ)

On Windows, use 'nvm-windows' by coreybutler (downloadable from GitHub releases), which provides identical functionality.

📌 Summary of Key Takeaways

  • ✓Use --legacy-peer-deps for stubborn peer dependency mismatches.
  • ✓Use NVM to switch Node versions seamlessly.

Official References & Further Reading