Most npm install errors look scary because the terminal prints a lot of text. The trick is to find the real error code first.

Common codes like ERESOLVE, ENOENT, and EACCES usually point to different problems. Do not randomly delete files until you know which one you have.

Quick answer

Start by finding the error code.

Error Usually means First thing to try
ERESOLVE Dependency versions conflict Read the conflicting packages and update one side
ENOENT npm cannot find a file or folder Check that package.json exists and path is correct
EACCES Permission denied Use a Node version manager or fix npm global permissions
ETARGET Version does not exist Check the package version
ENOTFOUND Network or registry issue Check internet, proxy, registry, or package name

If you only remember one rule: read the first error code before running fixes.

before fixing anything

Run these commands:

node -v
npm -v
pwd
ls

Then confirm the project has a package.json.

ls package.json

If there is no package.json, you may be in the wrong folder.

fix ERESOLVE unable to resolve dependency tree

ERESOLVE usually means two packages want incompatible versions of another package.

Example:

npm ERR! code ERESOLVE
npm ERR! Could not resolve dependency:
npm ERR! peer react@"17" from some-old-library

This means your project might use React 18 or 19, but one library expects React 17.

Better fix order:

  1. Read which package is causing the conflict.
  2. Check if that package has a newer version.
  3. Update the package if possible.
  4. If the package is old, replace it.
  5. Use --legacy-peer-deps only when you understand the risk.

Command:

npm install package-name@latest

Temporary workaround:

npm install --legacy-peer-deps

That can get you unstuck, but it may hide a real compatibility issue.

fix ENOENT no such file or directory

ENOENT means npm tried to open something that does not exist.

Common causes:

  • You are in the wrong directory.
  • package.json is missing.
  • A file path in package.json is wrong.
  • package-lock.json references something broken.
  • A package install was interrupted.

Try:

pwd
ls

If you are not in the project folder:

cd path/to/your/project
npm install

If node_modules is broken:

rm -rf node_modules package-lock.json
npm install

Use that only inside your project folder.

fix EACCES permission denied

EACCES means your user does not have permission to write where npm is trying to write.

This often happens with global installs on macOS or Linux.

Do not make sudo npm install -g your default habit. It can create more permission problems later.

Recommended approach:

  1. Install Node with a version manager like nvm, fnm, or volta.
  2. Reinstall dependencies.
  3. Avoid global installs when a local command works.

Example:

npx create-next-app@latest

Instead of installing create-next-app globally.

clean install checklist

Use this when the project is yours and you are okay regenerating dependencies:

rm -rf node_modules package-lock.json
npm cache verify
npm install

If the project is a team project, be careful before deleting package-lock.json. The lockfile helps everyone install the same dependency versions.

common mistake: deleting files too early

Many tutorials say “delete node_modules and package-lock.json” for everything.

Sometimes that works. Sometimes it hides the real issue.

Use this order:

Step Why
Read error code Finds the category
Read package names Finds the conflict
Check Node/npm versions Some projects require specific versions
Try targeted fix Safer than deleting everything
Clean install Useful when install state is broken

simple decision tree

Does package.json exist?
  no -> cd into the right folder
  yes -> read npm error code

ERESOLVE?
  update or replace conflicting package

ENOENT?
  check missing file/path and reinstall if needed

EACCES?
  fix Node/npm permissions with a version manager

final advice

Do not memorize every npm error. Learn how to read them.

Find the code, find the package, understand the cause, then choose the smallest fix.

npm documentation worth keeping nearby

verify the repair without hiding the cause

After an install succeeds, verify that it is reproducible rather than trusting one warm node_modules directory:

rm -rf node_modules
npm ci
npm test
npm run build

npm ci installs exactly what the committed lockfile describes and fails when package.json and package-lock.json disagree. That makes it a better final check for CI and deployment than another local npm install.

Do not finish by committing an unexplained --force, deleting the lockfile, or running every command with sudo. Record which package or path caused the failure and why the chosen change is valid. The next developer should be able to reproduce both the failure and the fix.

The references below describe npm’s supported commands and permission guidance. Prefer them over a copied command that does not explain which files or global directories it changes.