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

后端 未结 19 2114
温柔的废话
温柔的废话 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:48

    npm allows installing newer version of a package than the one specified. Using tilde (~) gives you bug fix releases and caret (^) gives you backwards-compatible new functionality as well.

    The problem is old versions usually don't receive bug fixes that much, so npm uses caret (^) as the default for --save.

    According to: "Semver explained - why there's a caret (^) in my package.json?".

    Note that the rules apply to versions above 1.0.0 and not every project follows semantic versioning. For versions 0.x.x the caret allows only patch updates, i.e., it behaves the same as the tilde. See "Caret Ranges"

    Here's a visual explanation of the concepts:

    semver diagram

    Source: "Semantic Versioning Cheatsheet".

提交回复
热议问题