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

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

    You probably have seen the tilde (~) and caret (^) in the package.json. What is the difference between them?

    When you do npm install moment --save, It saves the entry in the package.json with the caret (^) prefix.

    The tilde (~)

    In the simplest terms, the tilde (~) matches the most recent minor version (the middle number). ~1.2.3 will match all 1.2.x versions but will miss 1.3.0.

    The caret (^)

    The caret (^), on the other hand, is more relaxed. It will update you to the most recent major version (the first number). ^1.2.3 will match any 1.x.x release including 1.3.0, but will hold off on 2.0.0.

    Reference: https://medium.com/@Hardy2151/caret-and-tilde-in-package-json-57f1cbbe347b

提交回复
热议问题