node.js 当我运行 `npm install` 时,它返回 `ERR!代码完整性`(npm 5.3.0)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/47545940/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 18:36:13  来源:igfitidea点击:

When I run `npm install`, it returns with `ERR! code EINTEGRITY` (npm 5.3.0)

node.jsubuntunpm

提问by SANITH

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.jsonfile, and ran npm cache clean --force, but it didn't work.

我在运行时收到此错误sudo npm install。在我的服务器上,npm 是较早安装的。我试图删除该package-lock.json文件,然后运行npm cache clean --force,但它没有用。

My npm version is 5.3.0.

我的 npm 版本是 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

采纳答案by SANITH

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

其实以上是与服务器端的网络连接有关。当我在服务器中连接良好时,npm install 运行良好并且没有抛出任何错误

回答by SherylHohman

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

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

This worked for me:
npm cache verify

这对我有用:
npm cache verify

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

然后我重新运行:
npm install -g create-react-app

And it installed like as expected: Issue resolved

它按预期安装:问题已解决



Other solutions mentioned in the github issueinclude:

github问题中提到的其他解决方案包括:

npm cache clean --force

npm cache clean --force

OR

或者

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

删除Users%username%\AppData\Roaming(windows 7) 中的npm 和 npm-cache 文件夹并运行npm install

OR

或者

Update npm by via npm i -g npm

通过通过更新 npm npm i -g npm

OR

或者

Delete package-lock.json

删除 package-lock.json

OR

或者

npm cache verify

npm cache verify

OR

或者

npm cache clean

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.jsonfile.
  4. Delete _cacachedirectory 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
  1. 查找所有过时的软件包并更新主题:
    npm outdated -g
    sudo npm i -g outDatedPKG
  2. 使用以下命令将 npm 升级到最新版本:
    sudo npm i -g npm
  3. 删除package-lock.json文件。
  4. 删除_cacache目录~/.npmnpm cache verify
  5. 每次出现该错误时,请执行第 2 步和第 3 步。
  6. 如果仍然出现错误,请清除 npm 的缓存:
    npm cache clean --force

OR

或者

  1. Add proxy to .npmrcin ~directory:
  1. .npmrc~目录中添加代理:

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

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

  1. Try again! slow internet connection and censorship may cause this ugly problem.
  1. 再试一次!缓慢的互联网连接和可能会导致这个丑陋的问题。

OR

或者

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

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

OR

或者

npm config set package-lock false

npm config set package-lock false

回答by Gaurav Joshi

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

删除 package-lock.json 文件,然后尝试安装

回答by Mercury

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
  1. 错误的 package-lock.json 文件
  2. npm-shrinkwrap.json 与 package-lock.json 文件的存在

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)
  1. 删除了 package-lock.json 文件
  2. 删除 npm-shrinkwrap.json 文件
  3. 再次运行 npm install (重新创建了一个好的包锁文件)

Fixed my error!

修正了我的错误!

回答by sashoalm

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

问题确实在package-lock.json,并且在用另一个分支的工作版本替换它之后它起作用了。

What's interesting is seeing the diff:

有趣的是看到差异:

diff

差异

So there really is some integrity checksum in the package-lock.jsonto verify that the file you are downloading hasn't been tampered with. It's just that somehow the integrity checksum was replaced in our package-lock.jsonwith a SHA1 instead of a SHA-512 checksum. I have no idea how this happened.

所以确实有一些完整性校验和package-lock.json来验证您正在下载的文件没有被篡改。只是不知何故完整性校验和在我们中被替换package-lock.json为 SHA1 而不是 SHA-512 校验和。我不知道这是怎么发生的。

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 by the first two checksums in package-lock.json:

通过前两个校验和找到包package-lock.json

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

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

并将第三个校验和放入其“完整性”字段:

sha512-WXI95kpJrxw4Nnx8vVI90PuUhrQjnNgghBl5tn54rUNKZYbxv+4ACxUzPVpJEtWxKmeDwnQrzjc0C2bYmRJVKg==

A more detailed description is here.

更详细的描述在这里

回答by Kolaaa

Try the following:

请尝试以下操作:

npm cache clean --force

This has worked for me.

这对我有用。

回答by jfajunior

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.
  1. 删除 package-lock.json;
  2. 删除文件夹 AppData\Local\npm\cache 或 AppData\Roaming\npm\cache;
  3. 删除文件夹 node_modules.staging;
  4. 再次运行 npm install。

After that everything ran smoothly.

之后,一切顺利。

回答by Vanessa Ortiz

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 --verboseIf after following the above steps still the issue exists then please provide us the output of installation command with --verbose.
  1. 进入项目目录
  2. 删除 node_modules 目录: rm -rf node_modules
  3. 删除 package-lock.json 文件: rm package-lock.json
  4. 清除缓存: npm cache clean --force
  5. 运行npm install --verbose如果按照上述步骤操作后问题仍然存在,请使用 --verbose 向我们提供安装命令的输出。

回答by Sai Ram

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)

我正在使用私有 npm 注册表并尝试安装私有 npm 模块。登录到 npm 本地注册表修复了它(使用命令npm --add-user

回答by Raj

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!!

在深入研究 GitHub 问题后找到了这个答案!!