Caret vs Tilde in package.json
Organizing content I was curious about
Reference: blog.outsider.ne.kr
tilde (~)
: Approximately equivalent to version
Automatically updates only within the range of the last digit of the currently specified version
When you use
npm install MODULE_NAME --saveornpm install MODULE_NAME --save-devto automatically add dependencies to package.json, the default method used is the tilde(~) approachex)
~0.0.1:>=0.0.1 <0.1.0~0.1.1:>=0.1.1 <0.2.0~0.1:>=0.1.0 <0.2.0~0:>=0.0 <1.0
When the version is specified in various ways, it automatically updates within the ranges shown above
caret (^)
: Compatible with version
To explain Caret, you first need to know about Semantic Versioning (SemVer)
Node.js and all npm modules follow
SemVer
Meaning of npm version
Caret(
^) operates under the assumption that the Node.js module followsSemVerTherefore, MINOR or PATCH versions should maintain backward compatibility, so they are updated
ex)
^1.0.2:>=1.0.2 <2.0^1.0:>=1.0.0 <2.0^1:>=1.0.0 <2.0
Comparing with Tilde, the difference is clear: since backward compatibility is guaranteed within
1.x.x, it means it will update everything within that range
Wrap-up
~versionApproximately equivalent to version
Updates future PATCHes without increasing the MINOR version
ex)
~1.2.3: will use releases from1.2.3to<1.3.0
^versionCompatible with version
Updates future MINOR/PATCHes without increasing the MAJOR version
ex)
^2.3.4: will use releases from2.3.4to<3.0.0
Last updated