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

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

    I would like to add the official npmjs documentation as well which describes all methods for version specificity including the ones referred to in the question -

    https://docs.npmjs.com/files/package.json

    https://docs.npmjs.com/misc/semver#x-ranges-12x-1x-12-

    • ~version "Approximately equivalent to version" See npm semver - Tilde Ranges & semver (7)
    • ^version "Compatible with version" See npm semver - Caret Ranges & semver (7)
    • version Must match version exactly
    • >version Must be greater than version
    • >=version etc
    • <=version
    • 1.2.x 1.2.0, 1.2.1, etc., but not 1.3.0
    • http://sometarballurl (this may be the URL of a tarball which will be downloaded and installed locally
    • * Matches any version
    • latest Obtains latest release

    The above list is not exhaustive. Other version specifiers include GitHub urls and GitHub user repo's, local paths and packages with specific npm tags

提交回复
热议问题