Using tilde (~) in a dependency version on package.json specifies a patch or minor range to be installed

This article was published on Jan 18, 2021

When we define a version with Tilde range (~), it only gets a version from either the specified minor or patch version. For example:

"I want to install any minor from version 9.1 of this dependency"

{
  "dependencies": {
    "my-dependency": "~9.1"
  }
}

So it'll be installed always the latest patch version of 9.1.X of my-dependency.

"I want to install always the latest version 9 of my-dependency"

{
  "dependencies": {
    "my-dependency": "~9"
  }
}

Then it'll install the latest version 9.x.x (e.g 9.3.19) of this dependency. Always under than 10 but greater than 8.

Resources