Difference between Caret (^) and Tilde (~) in package.json. Did you know?
2022, Feb 16
The difference between a Caret and Tilde in package.json. Did you know it is simpler than it looks? and at the same time a nuance that you can easily forget?
Semantic Versioning
When working with package.json
and defining a strategy for how packages are updated, I always tend to forget the meaning of the symbols, so for our own sake, I'm documenting this here :)
Let's look at the following:
{
"prettier": "^2.3.1",
}
{
"prettier": "~2.3.1",
}
Both versions use Semantic Versioning, represented by the definition of MAJOR.MINOR.PATCH
.
MAJOR.MINOR.PATCH
2 .3 .1
So according to this table:
Symbol | Dependency | Versions | Changes |
---|---|---|---|
caret(^) | ^2.3.1 | 2.X.X | backwards compatibility, minor increment |
tilde(~) | ~2.3.1 | 2.3.X | bug fix |
Caret(^) allows for incremental changes of MINOR and PATCH:
Tilde(~) allows for incremental changes of PATCH only:
Feel free to save this reference for your own records.