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

后端 未结 19 1878
温柔的废话
温柔的废话 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条回答
  •  梦毁少年i
    2020-11-22 01:01

    ~ fixes major and minor numbers. It is used when you're ready to accept bug-fixes in your dependency, but don't want any potentially incompatible changes.

    ^ fixes the major number only. It is used when you're closely watching your dependencies and are ready to quickly change your code if minor release will be incompatible.

    In addition to that, ^ is not supported by old npm versions, and should be used with caution.

    So, ^ is a good default, but it's not perfect. I suggest to carefully pick and configure the semver operator that is most useful to you.

提交回复
热议问题