npm install not working? Here’s How to Fix Common npm Errors (2025 Guide)

Introduction

If you’ve worked with Node.js, you’ve probably run into the dreaded npm install errors. Whether it’s ELIFECYCLE, dependency conflicts, or permission issues, these errors always seem to pop up when you’re in a hurry.

The good news? Most of these problems have simple fixes.

In this 2025 updated guide, I’ll walk you through the most common npm errors developers face today and show you step-by-step solutions. Bookmark this page — it’ll save you hours of frustration in the future!


1. Error: npm ERR! code ELIFECYCLE

What It Looks Like

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! some-package@1.0.0 start: `node index.js`
npm ERR! Exit status 1

Why It Happens

This means the package you’re installing or running has a script that failed (for example, during npm install or npm start).

How to Fix It

✅ Step 1: Clean npm cache

npm cache clean --force

✅ Step 2: Delete node_modules and reinstall

rm -rf node_modules package-lock.json
npm install

✅ Step 3: Check Node.js and npm versions

node -v
npm -v

Update if necessary:

npm install -g npm@latest
nvm install <version>

✅ Step 4: Run with verbose flag to debug

npm install --verbose


2. Error: npm ERR! ERESOLVE unable to resolve dependency tree

What It Looks Like

npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree

Why It Happens

This happens when two or more packages require incompatible versions of the same dependency.

How to Fix It

✅ Step 1: Use legacy peer deps

npm install --legacy-peer-deps

✅ Step 2: Force install (not always recommended)

npm install --force

✅ Step 3: Manually resolve versions
Open package.json and adjust the conflicting versions. Then reinstall:

rm -rf node_modules package-lock.json
npm install


3. Error: EACCES: permission denied

What It Looks Like

npm ERR! Error: EACCES: permission denied, access '/usr/local/lib/node_modules'

Why It Happens

This usually happens on Linux or macOS when npm doesn’t have the correct permissions to install global packages.

How to Fix It

✅ Step 1: Avoid using sudo with npm (bad practice).
✅ Step 2: Change npm’s default directory:

mkdir ~/.npm-global
npm config set prefix '~/.npm-global'

✅ Step 3: Add the new path to your environment:

export PATH=~/.npm-global/bin:$PATH

✅ Step 4: Update your shell config (.bashrc, .zshrc, etc.) with the new path.


4. Error: “Global package not found”

What It Looks Like

command not found: nodemon

Why It Happens

You installed a global package but your system can’t find it.

How to Fix It

✅ Step 1: Check global npm directory

npm list -g --depth=0

✅ Step 2: Ensure it’s in your PATH

export PATH=$(npm config get prefix)/bin:$PATH

✅ Step 3: Reinstall the package globally

npm install -g nodemon


5. Error: “npm command not found”

What It Looks Like

bash: npm: command not found

Why It Happens

This means Node.js and npm aren’t properly installed or PATH isn’t configured.

How to Fix It

✅ Step 1: Verify installation

node -v
npm -v

✅ Step 2: Reinstall Node.js (recommended via nvm)

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
nvm install --lts

✅ Step 3: Restart terminal and try again.


6. Best Practices to Avoid npm Errors

  • Always use the latest LTS version of Node.js.
  • Delete node_modules and package-lock.json when facing weird issues.
  • Use npx instead of installing packages globally.
  • Keep your dependencies updated:
npm outdated
npm update

  • Consider alternatives like yarn or pnpm if your project supports them.

Conclusion

npm errors can be frustrating, but with the right fixes, you can resolve most issues in minutes.

👉 Save this page for future reference, and if you found it helpful, share it with your fellow developers.

Happy coding! 🚀

How to find what packages will be updated in package.json file ?

There is an npm command called npm outdated, which will tell us what packages will be updated.

Before running npm update command which will help us to updated packages, it is always better to run npm outdated first. So it will give you you list of packages with current version, wanted version and latest version.

Whenever we run npm update all packages will be updated to wanted versions which are listed when we run npm update command.

For Example, If you want to update a lodash package to its latest version we need use the following command.

After completion of installation, run the following command to check which version is installed for lodash.

How to publish a package to npm ?

To publish a package to npm, we should follow the following steps.

STEP 1 : Make sure your project have package.json file something like this.

STEP 2 : update your entry file with required functionality. Here entry file is index.js as we defined in package.json as “main”: “index.js”. Following is some example code.

STEP 3: signup to npm using https://www.npmjs.com/signup

STEP 4: Now login to npm using the following command in the terminal

STEP 5: publish the package using the following command. (Make sure package name is unique)

Finally you are able use that package anywhere by just installing with the following command

Showing Alert For Page Refresh , Closing tab or Window If Unsaved changes are there in the Form – ReactJS

If unsaved changes are there in the form, we will use the following code to show default alert message when user tries to reload or close the window or close the tab.

Error: [Reanimated] failed to create a worklet. – React Native

To fix this error, initially check your package.json file to find “react-native-reanimated”. if it is not installed, install it something like to “react-native-reanimated”: “^3.X.X”.

Now update your babel.config.js as follows

Now search for metro.config.js and update config as follows

const config = {
    resetCache: true
};

Now run the following command

Now it will work without that error.