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

Syket Bhattachergee
2 min readApr 10, 2023

--

In our everyday coding life, we use package.json a lot. When we install some packages, we see two symbols (~ and ^).
Do you know what does work these two symbols in the package.json file? Don’t worry I will clarify to you, what does work for both of them.

Suppose we have 3 types of package versions in our package.json file:

1. “react”: “¹⁸.2.1”
2. “react”: “~18.2.1”
3. “react”: “18.2.1”

Basically, we can see that right, in our package.json file. So, in that case, you can see in №1 We have caret(^), №2 we have tilde(~) and the last one is the normal version of the package.

№1 = Caret (^)
^version “Compatible with version”, will update you to all future minor/patch versions, without incrementing the major version. ^2.3.4 will use releases from 2.3.4 to ❤.0.0.

№2 = Tilde (~)
~version “Approximately equivalent to version”, will update you to all future patch versions, without incrementing the minor version. ~1.2.3 will use releases from 1.2.3 to <1.3.0.

№3 = Normal Version

For no 3 we are saying package.json file to we need this specific version. Very specifically, we don’t care if a new version is released or not. We only need this specific version in our application.

So, this is the simple overview of the caret, tilde, and normal version of the package in the package.json file.

I am Syket Bhattachergee, a passionate Software engineer. You can contact me on Website, X/Twitter, or LinkedIn, and follow my work on GitHub.

let’s connect and collaborate!🤝

--

--

Syket Bhattachergee

Passionate programmer sharing insights on coding. Engaging articles cover topics for beginners & experienced developers.