Open In App

How to Fix npm ERR! code EINTEGRITY?

Last Updated : 04 Jul, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

When working with Node.js and NPM we might see various errors that can be confusing and interrupt development workflow. One such error is npm ERR! code EINTEGRITY. This error typically arises due to the integrity checks failing during the installation of the NPM packages.

The npm ERR! code EINTEGRITY error occurs when there is a mismatch between the integrity hash of the downloaded package and the expected hash. This mismatch can happen due to the various reasons such as network issues corrupted cache or changes in the package registry.

wtt

Showing the Problem

Imagine we are trying to install a package. For example, lodash using the following command:

npm install lodash

We might get an error message similar to the one shown below:

npm ERR! code EINTEGRITY
npm ERR! sha512-MKiLiV+I1AA596t9w1sQJ8jkiSr5+ZKi0WKrYGUn6d1F.......

npm ERR! A complete log of this run can be found in:
npm ERR! /home/ubuntu/.npm/_logs/2017-11-29T05_33_52_182Z-debug.log

To solve the npm ERR! code EINTEGRITY error, we will follow a systematic approach:

Clear the NPM Cache

The NPM cache stores downloaded packages to speed up the installation process. Sometimes, the cache can become corrupted leading to the integrity errors. Clearing the NPM cache can resolve this issue.

npm cache clean --force

After clearing the cache, try reinstalling the package:

npm install lodash

Reinstall the Package

If clearing the cache does not work, we can try reinstalling the package directly.

npm uninstall lodash
npm install lodash

Update NPM to the Latest Version

Ensure that, we are using the latest version of the NPM as bugs and issues are often fixed in newer releases.

npm install -g npm@latest

After updating NPM, try installing the package again.

npm install lodash

Delete node_modules and package-lock.json

If the problem persists delete the node_modules directory and package-lock.json file then reinstall all dependencies. This approach can resolve deeper issues with the package dependencies.

rm -rf node_modules package-lock.json
npm install

Verify NPM Registry Integrity

Ensure that the NPM registry, we are using is reliable and not causing the integrity issues. We can switch to the different registry if needed.

npm config set registry https://registry.npmjs.org/

Then, try reinstalling the package:

npm install lodash

Note: We have used Lodash npm package to show the error and solutions. You can apply those solutions for any node module.

Conclusion

The NPM ERR! code EINTEGRITY error can be frustrating but it is usually resolvable by following a systematic approach. By clearing the NPM cache reinstalling packages, updating NPM and verifying the NPM registry, we can fix this error and get back to the development work. Regularly updating NPM and maintaining a clean cache can help prevent such issues in the future.


Next Article

Similar Reads