Difference between Caret (^) and Tilde (~) in package.json. Did you know?

• JavaScript, Node.js, NPM, Package Management, Semantic Versioning • 1 min read

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:

1
2
3
{
    "prettier": "^2.3.1",
}
1
2
3
{
    "prettier": "~2.3.1",
}

Both versions use Semantic Versioning, represented by the definition of MAJOR.MINOR.PATCH.

1
2
MAJOR.MINOR.PATCH
2    .3    .1

So according to this table:

SymbolDependencyVersionsChanges
caret(^)^2.3.12.X.Xbackwards compatibility, minor increment
tilde(~)~2.3.12.3.Xbug fix

Caret(^) allows for incremental changes of MINOR and PATCH:

Caret

Tilde(~) allows for incremental changes of PATCH only:

Tilde

Feel free to save this reference for your own records.

Comments & Discussion

Join the conversation! Share your thoughts and connect with other readers.