Version Ranges: Caret (^) vs Tilde (~)
How npm decides which version to install when a package is updated.
What are version ranges?
When you run npm install react, npm doesn't lock your package.json to the exact version it downloaded (e.g., 18.2.0). Instead, it adds a **version range** (e.g., ^18.2.0).
A version range tells npm how aggressive it should be about automatically upgrading your dependencies when new versions are published to the registry.
The two most common range specifiers are the Caret (^) and the Tilde (~).
Why does it matter?
If every package was locked to an exact version (e.g., 18.2.0), you would never receive automatic bug fixes or security patches.
However, if ranges were too loose (e.g., *), a breaking API update could slip into your project and crash your build.
The Caret and Tilde strike a balance, leveraging the rules of SemVer to allow safe updates while blocking dangerous ones.
How they resolve
The **Caret (^)** allows updates that do not modify the leftmost non-zero digit. For ^1.2.3, this allows MINOR and PATCH updates (up to, but not including, 2.0.0). This is npm's default because it safely delivers new features and bug fixes.
The **Tilde (~)** is more conservative. If a minor version is specified, it allows ONLY PATCH updates. For ~1.2.3, it will accept 1.2.4 and 1.2.99, but will block 1.3.0.
Exact versions (e.g., 1.2.3 with no prefix) lock the dependency entirely. No updates will occur unless explicitly requested.
Version Resolver Simulator
Use the interactive version resolver below to see exactly which simulated releases are allowed or blocked based on your chosen range.
1. Select Range Prefix
2. Select Base Version
"dependencies": {
"lodash": "^1.2.3"
}
Resolution SimulatorTargeting ^1.2.3
Remember this
- Caret (^) allows Minor and Patch updates (changes that don't affect the leftmost non-zero digit).
- Tilde (~) allows Patch updates only (strict bug fixes).
- Exact version (no prefix) locks the package completely.
- For unstable 0.x.x packages, Caret (^) restricts updates to Patch only.
Done with this concept?
Mark it complete to track your progress. No login needed.