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

后端 未结 19 1848
温柔的废话
温柔的废话 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 00:51

    Not an answer, per se, but an observation that seems to have been overlooked.

    The description for carat ranges:

    see: https://github.com/npm/node-semver#caret-ranges-123-025-004

    Allows changes that do not modify the left-most non-zero digit in the [major, minor, patch] tuple.

    Means that ^10.2.3 matches 10.2.3 <= v < 20.0.0

    I don't think that's what they meant. Pulling in versions 11.x.x through 19.x.x will break your code.

    I think they meant left most non-zero number field. There is nothing in SemVer that requires number-fields to be single-digit.

提交回复
热议问题