I recently ran npm install
(npm 1.4.3) with the --save-dev
flag and the package entries it added to my package.json all began with a ^
, e.g. "^2.5.0"
. I have never seen this before with the earlier versions of npm I have used, and I cannot find any documentation for this notation, only for the notations I'm already familiar with, e.g. ~
, >=
etc.. What does it mean?
Tilde(~) notation Caret(^) notation. Used for Approximately equivalent to version. Used for Compatible with version. It will update you to all future patch versions, without incrementing the minor version.
The syntax is in JSON format where the key is the name of the package and the value is the version of the package to be used. npm uses the package. json file to specify the version of a package that your app depends on. The version number is in semver syntax which designates each section with different meaning.
For example a dependency with a version of * would equate to any version that was greater than or equal to 0.0. 0, while 1. * would allow versions greater than or equal to 1.0. 0 and less than 2.0.
x.x versions are special: the first non-zero component indicates potentially breaking changes, meaning the caret operator matches any version with the same first non-zero component starting at the specified version. ^0.0. 2 := =0.0. 2 "Only the version 0.0. 2 is considered compatible"
Quoting from isaacs/node-semver:
- ^1.2.3 := >=1.2.3-0 <2.0.0-0 "Compatible with 1.2.3". When using caret operators, anything from the specified version (including prerelease) will be supported up to, but not including, the next major version (or its prereleases). 1.5.1 will satisfy ^1.2.3, while 1.2.2 and 2.0.0-beta will not.
- ^0.1.3 := >=0.1.3-0 <0.2.0-0 "Compatible with 0.1.3". 0.x.x versions are special: the first non-zero component indicates potentially breaking changes, meaning the caret operator matches any version with the same first non-zero component starting at the specified version.
- ^0.0.2 := =0.0.2 "Only the version 0.0.2 is considered compatible"
That said, I would recommend to use "~" instead because it has more intuitive semantics, see discussion in npm/npm#4587.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With