249

I am getting this error while running sudo npm install. On my server, npm was installed earlier. I've tried to delete the package-lock.json file, and ran npm cache clean --force, but it didn't work.

My npm version is 5.3.0.

The error:

npm ERR! code EINTEGRITY
npm ERR! sha512-MKiLiV+I1AA596t9w1sQJ8jkiSr5+ZKi0WKrYGUn6d1Fx+Ij4tIj+m2WMQSGczs5jZVxV339chE8iwk6F64wjA== integrity checksum failed when using sha512: wanted sha512-MKiLiV+I1AA596t9w1sQJ8jkiSr5+ZKi0WKrYGUn6d1Fx+Ij4tIj+m2WMQSGczs5jZVxV339chE8iwk6F64wjA== but got sha512-WXI95kpJrxw4Nnx8vVI90PuUhrQjnNgghBl5tn54rUNKZYbxv+4ACxUzPVpJEtWxKmeDwnQrzjc0C2bYmRJVKg==. (65117 bytes)

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
Ulrich Eckhardt
  • 16,572
  • 3
  • 28
  • 55
SANITH
  • 3,147
  • 3
  • 13
  • 15

34 Answers34

377

See https://github.com/npm/npm/issues/16861

This worked for me:
npm cache verify

Then I re-ran:
npm install -g create-react-app

And it installed as expected: Issue resolved.


Other solutions mentioned in the GitHub issue include:

npm cache clean --force

OR

Deleting npm and npm-cache folders in Users%username%\AppData\Roaming (Windows 7 and Windows 10) and running npm install

OR

Update npm by via npm i -g npm

OR

Delete package-lock.json

OR

npm cache clean

OR

Do these steps to fix the problem:

  1. Find all outdated packages and update theme:
    npm outdated -g
    sudo npm i -g outDatedPKG
  2. Upgrade npm to latest version with:
    sudo npm i -g npm
  3. Delete package-lock.json file.
  4. Delete _cacache directory in ~/.npm: npm cache verify
  5. Every time I get that error, do steps 2 & 3.
  6. If you still get the error, clear npm's cache:
    npm cache clean --force

OR

  1. Add proxy to .npmrc in ~ directory:

proxy=http://localhost:8123
https-proxy=http://localhost:8123

  1. Try again! slow internet connection and censorship may cause this ugly problem.

OR

npm cache clear --force && npm install --no-shrinkwrap --update-binary

OR

npm config set package-lock false

erikvold
  • 15,988
  • 11
  • 54
  • 98
SherylHohman
  • 16,580
  • 17
  • 88
  • 94
  • 1
    Thank you! That was very helpful and I solved my problem choosing some of the given options. – jfajunior Apr 26 '18 at 08:02
  • Super !! So Glad to Help :-) – SherylHohman Apr 26 '18 at 09:57
  • 3
    Sheryl, first: thanks for taking the time to answer this. It's clear your answer was helpful to people. Can I ask you what each of these alternatives does, and why some may work when others don't? Thanks! – Andres F. May 07 '18 at 19:18
  • 1
    @AndresF. I do not have a deep understanding of how the underbelly of yarn works, or when/why some methods work over others. In some cases they essentially accomplish the same thing, but go about triggering it in a different way. I linked to the github issue where all these solutions were presented - it is the source of the compiled list in my answer. I suggest research into the underbelly of yarn and npm, or checking out the github issue linked, perhaps reaching out to individual authors if necessary. – SherylHohman May 07 '18 at 21:27
  • In case, any update in node js version in local machine, It will through this error. – gnganapath Jan 02 '19 at 08:11
  • One of these 87 different things to try worked for me! – Catfish Mar 14 '19 at 23:19
  • tried many things but only this worked out `npm cache clean --force` – Ali Apr 26 '20 at 19:30
  • I followed these steps: 1. npm i -g npm 2. delete package-lock.json file 3. delete node_modules folder 4. npm cache clean --force 5. npm cache verify 6. npm install – AbhimanuSharma Sep 07 '20 at 05:56
  • Our company's artifactory(where we pull our npm node modules) was missing a version of a node module which one of our npm dependencies used. Got them to update it for the win! – RayLoveless Apr 21 '21 at 17:38
77

Delete package-lock.json file and then try to install

Gaurav Joshi
  • 964
  • 6
  • 12
47

The issue was indeed in package-lock.json, and after replacing it with a working version from another branch it worked.

What's interesting is seeing the diff:

diff

So there really is some integrity checksum in the package-lock.json and it was replaced in our package-lock.json with a SHA1 instead of a SHA-512 checksum. See here for more info.

In case you don't have a working version in another branch. Consider the message

npm ERR! code EINTEGRITY
npm ERR!
  sha512-MKiLiV+I1AA596t9w1sQJ8jkiSr5+ZKi0WKrYGUn6d1Fx+Ij4tIj+m2WMQSGczs5jZVxV339chE8iwk6F64wjA==
integrity checksum failed when using sha512: wanted
  sha512-MKiLiV+I1AA596t9w1sQJ8jkiSr5+ZKi0WKrYGUn6d1Fx+Ij4tIj+m2WMQSGczs5jZVxV339chE8iwk6F64wjA==
but got
  sha512-WXI95kpJrxw4Nnx8vVI90PuUhrQjnNgghBl5tn54rUNKZYbxv+4ACxUzPVpJEtWxKmeDwnQrzjc0C2bYmRJVKg==
. (65117 bytes)

Find the package in package-lock.json using the first checksum:

sha512-MKiLiV+I1AA596t9w1sQJ8jkiSr5+ZKi0WKrYGUn6d1Fx+Ij4tIj+m2WMQSGczs5jZVxV339chE8iwk6F64wjA==

and put the third checksum into its "integrity" field:

sha512-WXI95kpJrxw4Nnx8vVI90PuUhrQjnNgghBl5tn54rUNKZYbxv+4ACxUzPVpJEtWxKmeDwnQrzjc0C2bYmRJVKg==

A more detailed description is here.

sashoalm
  • 75,001
  • 122
  • 434
  • 781
  • where is package-lock.json file? – Mamen Apr 29 '18 at 09:58
  • @Mamen in the root directory of your app, next tp package.json. package.json lists the dependencies (packages) your app needs in order to compile/run. When you run `yarn install` or `yarn`, the packages listed in that file will be downloaded and installed, so the project/app can be run. The "lock" file is one difference between npm and yarn, ensuring package versions, and integrity. – SherylHohman Apr 30 '18 at 17:28
  • 2
    The only solution that came close to solving it for me. Deleting `package-lock.json` should remedy it as well. At least in my case. Although that is apparently not desirable. And to be fair I must mention here that OP tried to delete the file, so the case that this answer addresses is probably somewhat different. – x-yuri May 29 '20 at 00:29
37

Actually the above is related to the network connectivity in side the server. When I've good connectivity in the server, the npm install gone good and didn't throw any error

SANITH
  • 3,147
  • 3
  • 13
  • 15
18

My problem was 2 things:

  1. Bad package-lock.json file
  2. The existance of npm-shrinkwrap.json together with the package-lock.json file

What i did is:

  1. Deleted the package-lock.json file
  2. Delete the npm-shrinkwrap.json file
  3. Ran npm install again (which recreated a good package-lock file)

Fixed my error!

Mercury
  • 7,430
  • 3
  • 42
  • 54
11

I was stuck at this for a long time and this is what helped me.

Try this:

npm cache clean --force
npm install --update-binary --no-shrinkwrap

Found this answer after digging into GitHub issues!!

Raj
  • 3,637
  • 8
  • 29
  • 52
6

As a workaround, follow the below steps:

  1. Go to the project directory
  2. Remove the node_modules directory: rm -rf node_modules
  3. Remove package-lock.json file: rm package-lock.json
  4. Clear the cache: npm cache clean --force
  5. Run npm install --verbose If after following the above steps still the issue exists then please provide us the output of installation command with --verbose.
eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Vanessa Ortiz
  • 69
  • 1
  • 2
4

There are several valid and helpful responses here, but I would like to add that in my case the simplest solution was:

  1. Delete package-lock.json;
  2. Remove folder AppData\Local\npm\cache or AppData\Roaming\npm\cache;
  3. Remove folder node_modules.staging;
  4. Run npm install again.

After that everything ran smoothly.

jfajunior
  • 1,211
  • 1
  • 15
  • 19
3

I had a very similar problem, and in my case it worked by doing:

npm clean

This is the nuclear option since it clears every package from the cache as expained here.

Sebastian D'Agostino
  • 1,575
  • 2
  • 27
  • 44
3

Try the following:

npm cache clean --force

This has worked for me.

Blackbam
  • 17,496
  • 26
  • 97
  • 150
Kolaaa
  • 248
  • 3
  • 6
  • 6
    This does not add any value to the answers that are already here. The most highly up-voted comment already mentions `npm cache clean --force`, so this answer just reads as noise. – Blue Aug 05 '18 at 02:29
  • 3
    While this code may answer the question, providing additional context regarding how and/or why it solves the problem would improve the answer's long-term value. – Donald Duck Aug 05 '18 at 03:22
3

I was using private npm registry and trying to install private npm module. Logging to npm local registry fixed it (used command npm --add-user)

Sai Ram
  • 4,196
  • 4
  • 26
  • 39
3

Updating .npmrc and the registry to https:// worked for me

registry=https://registry.npmjs.org/
Matthew Blewitt
  • 459
  • 1
  • 3
  • 15
3

This Worked for me . open the project in CMD the run

npm cache verify 
npm install 
npm start
Aleks-Daniel Jakimenko-A.
  • 10,335
  • 3
  • 41
  • 39
Insookwa
  • 89
  • 1
  • 5
1

SherylHohman's answer solved the issue I had, but only after I switched my internet connection. Intitially, I was on the hard-line connection at work, and I switched to the WiFi connection at work, but that still didn't work.

As a last resort, I switched my WiFi to a pocket-WiFi, and running the following worked well:

npm cache verify

npm install -g create-react-app

create-react-app app-name

Hope this helps others.

SherylHohman
  • 16,580
  • 17
  • 88
  • 94
AJ Singh
  • 31
  • 4
1

I am behind my organization's proxy, running the following commands fixed the issue for me

npm config set proxy http://proxy.yourproxydomain.com:port
npm config set https-proxy http://proxy.yourproxydomain.com:port
npm config set strict-ssl false
npm config set registry https://registry.npmjs.org/
user3966432
  • 378
  • 3
  • 15
1

This was not yet mentioned but make sure that your SYSTEM TIME is correct. If it is too out of sync it will cause a EINTEGRITY error. When you are doing npm publish / install.

Chad Cache
  • 9,668
  • 3
  • 56
  • 48
1

None of the above answers worked for me. The solution to my issue was to change the way the snapshot dependency was consumed inside the package.json. Use the following template to pull in the snapshot dependency that you need

"dependency": "git+http://github.com/[pathtoproject].git#[branchname]",
Zach Pedigo
  • 396
  • 2
  • 9
1

I had the same issue. I used yarn instead of npm to install the dependencies and it worked.

yarn add *****
biggest_boy
  • 381
  • 4
  • 23
1

After going through all the answers and executing most of them. Although I resisted to try the Restart magic, eventually, the issue is solved after restart on my macbook(MacOS Catalina Ver. 10.15.7).

It seems like a cache issue indeed but none of the commands that I have executed cleared the cache.

myxlptlk
  • 139
  • 3
1

What worked for me was npm cache verify then re-run your command. All should be good.

0

Updating the .npmrc files' entries for scoped and un-scoped packages worked for me. So I ended up using the

npm config set @scope_name:registry SCOPED_REGISTRY_URL

and

npm config set registry PUBLIC_REGISTRY_URL

Ketcomp
  • 434
  • 6
  • 20
0

You should check Connection-specific DNS Suffix when type “ipconfig” or “ifconfig” in terminal

0

I faced same issue. Plus while I was trying to resolve from picking solutions from other devs, I faced few more issues like one listed here.

Angular 9 ng new myapp gives error The Schematic workflow failed

https://medium.com/@codewin/npm-warn-deprecated-request-2-88-2-b6da20766fd7

Finally after trying cache clean and verify and reinstall node of different versions and npm update, nvm and many other solution like set proxy and better internet connection, I still could not arrive to a resolve.

What worked for me is : I browsed a bit inside my C:\Users--- folder, I found package-lock.json and .npmrc files. I deleted those and reinstalled angular and tried. npm install and uninstall of different modules started working.

issue while creating using <code>ng new sample-app</code>

code_Jammy
  • 17
  • 1
  • 8
0

Before i was running this command

npm install typescript -g

after changing the command it worked perfectly.

npm install -g typescript
Jaimil Patel
  • 1,301
  • 6
  • 13
0

I faced this issue. It was my network connectivity. I changed network (from Broadband WiFi to 4G WiFi) and tried. It worked.

My broadband ISP was blocking all http requests. That might be the reason I guess in my case.

Mani Bharathy
  • 117
  • 1
  • 2
  • 13
0

all solutions failed for me till i checked router settings; it was set to only IPV4.. i changed and put ipv4v6 and all is working fine now.

0

In my case the sha command was missing from my linux distro; steps were

  • added the packages for sha512 (on my distro sudo apt install hashalot)
  • npm cache verify
  • rm -rf node_modules
  • npm install
dancl
  • 689
  • 5
  • 13
0

Easy and fast fix for me was to npm install the specific package on which it said the sha is wrong. Say your package is called awesome-package.

My solution was:

npm i awesome-package

This updated my sha within the package-lock.json.

Sinan Samet
  • 6,432
  • 12
  • 50
  • 93
0

If none of the above solved your problem, then just upgrade your npm verion and try. It worked for me.

0

Updating nodejs version worked for me.

curl -fsSL https://deb.nodesource.com/setup_12.x | sudo -E bash - sudo apt-get install -y nodejs

rjhcnf
  • 762
  • 6
  • 12
0

The issue occurred for me during an upgrade to node 18 - my package-lock file was holding onto a stale resolution from a custom registry our team no longer used.

Unforutnately, removing package lock, clearing the cache and running npm install were not enough.

Deleting the stale resolutions in package-lock followed by npm install fix the issue for me.

Here I deleted the line beginning with "resolved":

// package-lock.json

     "node_modules/closest-file-data": {
       "version": "0.1.4",
-      "resolved": "https://foo.foobar.io/foo/api/npm/npm-dev/closest-file-data/-/closest-file-data-0.1.4.tgz"
,
       "integrity": "sha1-l1+HwTLymdJKA3W59jyj+4j3Kzo=",

Generally you want to avoid manual changes to this file but my machine kept insisting I use the cached package

random-forest-cat
  • 33,652
  • 11
  • 120
  • 99
-1

Run the commands below on your project..

npm rm -rf node_modules && npm rm package-lock.json && npm rm -rf ~/.npm && npm install --update-binary --no-shrinkwrap
General Omosco
  • 606
  • 1
  • 10
  • 20
-1

We had this problem multiple times in the company I work at. Deleting the node_modules folder from the .nvm folder fixed the problem:

rm -rf ~/.nvm/versions/node/v8.6.0/lib/node_modules
Technotronic
  • 8,424
  • 4
  • 40
  • 53
  • Tried this (out of desperation) and now I'm getting: ``` ~/dev/mixmax/compose jordi/MV3-56-load-views-in-iframes$ npm --version -bash: /Users/jordi/.nvm/versions/node/v12.22.6/bin/npm: No such file or directory ``` – jsalvata Sep 21 '22 at 14:00
-1

Try this

  Step-1) Delete package-lock.json from root folder.
  Step-2) Delete node_modules folder
  Step-3) run npm install command in root
Jitendra Suthar
  • 2,111
  • 2
  • 16
  • 22