同事遇到这个问题
+ npm install --no-optional --production
npm ERR! code EINTEGRITY
npm ERR! sha512-nADAsJGM8jw18ufzd8/a26rC/+JVJCpLFH3fUkkxaXyMvDoAK99BDdAL5UqN9XZUj85nwM/3Lxbw8N9BRppFGA== integrity checksum failed when using sha512: wanted sha512-nADAsJGM8jw18ufzd8/a26rC/+JVJCpLFH3fUkkxaXyMvDoAK99BDdAL5UqN9XZUj85nwM/3Lxbw8N9BRppFGA== but got sha512-s9YhDRKaBS2uLucU30Cy5td+81hr1Vj+rn0m7b1U7mpcUNPUNwil7ifZS6m5b1Jqy6jh86WrRr37GqCmd3Lpqw==. (7539 bytes)
npm 包的校验值被变更,导致不一致(integrity: A sha512 or sha1 Standard Subresource Integrity string for the artifact that was unpacked in this location.)
临时解决方案是使用 npm config set package-lock false
这个可能是私有库选择的版本策略不正确, 需要设置为禁止覆盖。如果被同一版本的包被修改覆盖了,就会导致校验值不一致
nexus 版本策略:允许覆盖、禁止覆盖、只读。(向nexus服务发布NPM包时,使用的策略)
改为以上方案后,删除 package-lock.json,执行 npm cache clean —force 重新安装依赖,发布,还是报 npm ERR! code EINTEGRITY
+ npm install --no-optional --production
npm ERR! sha512-u9bxXv/UdLofvLRmJFK1fxoGwAEWuGtCxtwu9iQZwP5HDTRdY1zs9exWwVm/7+M83xjiB4xjUQDXHn8ypC864A== integrity checksum failed when using sha512: wanted sha512-u9bxXv/UdLofvLRmJFK1fxoGwAEWuGtCxtwu9iQZwP5HDTRdY1zs9exWwVm/7+M83xjiB4xjUQDXHn8ypC864A== but got sha512-s9YhDRKaBS2uLucU30Cy5td+81hr1Vj+rn0m7b1U7mpcUNPUNwil7ifZS6m5b1Jqy6jh86WrRr37GqCmd3Lpqw==. (7539 bytes)
可能第一次没执行好,我重新执行后,package-lock.json 又有变化,重新提交好了,执行脚本如下
rm -rf node_modules
npm cache verify
npm cache clean --force
npm i
# 之后重新提交代码,成功
参考:
- https://bbchin.com/archives/npm-checksum
- https://platformengineer.com/fix-npm-err-code-eintegrity-verification-failed-error/
- https://segmentfault.com/a/1190000040810501
- 推荐:https://stackoverflow.com/questions/47545940/when-i-run-npm-install-it-returns-with-err-code-eintegrity-npm-5-3-0
- https://github.com/npm/cli/issues/473