起因
在使用 Travis Ci 构建 Hexo 时出现了构件失败的情况,报错信息为 :
error Your lockfile needs to be updated, but yarn was run with `--frozen-lockfile`.
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
The command "eval yarn --frozen-lockfile " failed. Retrying, 2 of 3.
分析
Travis Ci 构建 Nodejs 项目的时候,默认使用了 yarn 作为 npm 的替换安装方式。但是在 2020 年 2 月份之前,默认的安装指令为:
$ yarn
但是之后 Travis Ci 修改了默认的安装指令,将其更改为:
$ yarn --frozen-lockfile
yarn --frozen-lockfile
与yarn
指令的区别在于:前者锁定当前依赖包的版本号,其进行的操作就是按照 yarn-lock.json 去安装。但是当一个依赖包拥有新版本时,yarn 为了防止开发者一直使用老旧版本的依赖,就会报出警告,就像我们遇到的问题那样。
解决方案
我们可以修改 .travis.yml 安装部分的脚本,来取消使用 --frozen-lockfile 指令:
install:
- yarn
同时需要保证node_js再10.0版本以上!
node_js:
- "10"