What's the difference between tilde(~) and caret(^) in package.json?

后端 未结 19 1860
温柔的废话
温柔的废话 2020-11-22 00:31

After I upgraded to latest stable node and npm, I tried npm install moment --save. It saves the entry in the package.json

19条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-22 01:02

    Related to this question you can review Composer documentation on versions, but here in short:

    • Tilde Version Range (~) - ~1.2.3 is equivalent to >=1.2.3 <1.3.0
    • Caret Version Range (^) - ~1.2.3 is equivalent to >=1.2.3 <2.0.0

    So, with Tilde you will get automatic updates of patches but minor and major versions will not be updated. However, if you use Caret you will get patches and minor versions, but you will not get major (breaking changes) versions.

    Tilde Version is considered "safer" approach, but if you are using reliable dependencies (well-maintained libraries) you should not have any problems with Caret Version (because minor changes should not be breaking changes.

    You should probably review this stackoverflow post about differences between composer install and composer update.

提交回复
热议问题