yarn upgrade为什么不更新package.json

December 10, 2019 ... ☕️ 2 min read

项目跑一段时间,或者想支持新特性,或者单纯怕被人说太out,就想把依赖包升级到较新版。Yarn upgrade即用于升级依赖。


  "css-loader": "^3.2.1",

yarn upgrade: Upgrades packages to their latest version based on the specified range.

直接运行yarn upgrade css-loader,输出


看起来很完美,升级到了3.3.0。但是,打开package.json,还是"css-loader": "^3.2.1",emmmm…😕

yarn list看看

yarn list




yarn upgrade为什么不更新package.json?

The package.json file will be updated to reflect the latest version range. By default, the existing range specifier in package.json will be reused if it is one of: ^, ~, <=, >, or an exact version. Otherwise, it will be changed to a caret (^). One of the flags —caret, —tilde or —exact can be used to explicitly specify a range.

翻译一下:如果package.json对应的包名版本,包含了^, ~, <=, >符号,就会重用,否则更新。WTF…

如果用yarn upgrade css-loader --latest


The upgrade —latest command upgrades packages the same as the upgrade command, but ignores the version range specified in package.json. Instead, the version specified by the latest tag will be used (potentially upgrading the packages across major versions)

啥是major versions?比如版本是1.2.3,1就是major version,2是minor version,3是revision(或subminor version)。

yarn upgrade-interactive


可以把这个命令看做yarn outdatedyarn upgrade的组合命令。



执行yarn upgrade-interactive css-loader --latest,然后根据交互,选择一个。

或者干脆yarn add css-loader吧。


SideEffect is a blog for front-end web development.
Code by Axiu / rss