从缓存中获取时完整性不正确

Incorrect integrity when fetching from the cache

当 运行 yarn add --dev jest 时,我得到了 错误 从缓存中提取时完整性不正确

完整输出:

tests (master)$ yarn add --dev jest
yarn add v1.19.0
info No lockfile found.
[1/4] Resolving packages...
warning jest > jest-cli > jest-config > jest-environment-jsdom > jsdom > left-pad@1.3.0: use String.prototype.padStart()
[2/4] Fetching packages...
error Incorrect integrity when fetching from the cache
info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.

我尝试删除 node_modules、重新运行 yarn installyarn add --dev jest 无济于事。

我该如何解决这个问题?

yarn cache clean

要解决此问题,运行:

yarn cache clean
yarn add --dev jest

来自yarn cache documentation

yarn cache clean [<module_name...>]

Running this command will clear the global cache. It will be populated again the next time yarn or yarn install is run. Additionally, you can specify one or more packages that you want to clean.

您还可以通过 yarn cache dir 查看缓存的位置。

yarn cache dir

Running yarn cache dir will print out the path where yarn’s global cache is currently stored.

Yarn 缓存清理没有帮助。我们必须在服务器上降级 yarn 版本。

原来是使用私有包的问题

GitHub Yarnpkg - "Incorrect integrity when fetching from the cache" #7584

对于使用 heroku 并看到此错误的任何人:

  • 安装 heroku cli
  • 通过heroku login
  • 登录
  • heroku plugins:install heroku-repo
  • heroku repo:purge_cache -a $YOURAPPNAME

然后进行手动重建

尝试升级 yarn,它解决了我的问题。可能是兼容性问题

yarn policies set-version

将下载最新的稳定版本

参考:纱线文档https://yarnpkg.com/lang/en/docs/cli/policies/#toc-policies-set-version

清理缓存并重新安装:

yarn cache clean
yarn install -f

安装包前需要运行这两条命令:

  • yarn config set unsafe-disable-integrity-migration false
  • yarn cache clean