^ (caret) allows minor and patch updates. ~ (tilde) allows patch updates only.
Versions follow semantic versioning (semver): MAJOR.MINOR.PATCH.
- Major: breaking changes.
- Minor: new features that stay backward-compatible.
- Patch: fixes that stay backward-compatible.
The ranges:
^1.4.2allows anything compatible with 1.4.2 that does not change the leftmost non-zero part:>=1.4.2 <2.0.0. This is the default thatnpm installwrites.~1.4.2allows patch updates only:>=1.4.2 <1.5.0.- A bare
1.4.2pins that exact version.
For 0.x versions, the caret is stricter, because npm treats a minor bump as breaking. So ^0.4.2 means >=0.4.2 <0.5.0.
Ranges decide what may be installed. The lockfile decides what is actually installed.
- Semver versions have the form MAJOR.MINOR.PATCH.
^1.4.2allows minor and patch updates, up to<2.0.0.~1.4.2allows patch updates only, up to<1.5.0.- On
0.xversions, the caret only allows patch updates within that minor version. On0.0.xversions, it pins the exact version. - An exact version pins it. The lockfile records the versions actually installed.
Read more