Pre-release Version Ordering in SemVer

How pre-release versions like 1.0.0-alpha.1, 1.0.0-beta.2, and 1.0.0-rc.1 are ordered. Numeric vs string identifiers and precedence rules.

Pre-release

Detailed Explanation

Pre-release Version Ordering

Pre-release versions are denoted by appending a hyphen and a series of dot-separated identifiers after the patch version: 1.0.0-alpha.1.

Key Rules

  1. Pre-release < Release: 1.0.0-alpha < 1.0.0
  2. Left-to-right comparison: Identifiers are compared one by one from left to right
  3. Numeric < String: A numeric identifier always has lower precedence than a string identifier
  4. Numeric comparison: Identifiers consisting of only digits are compared as integers
  5. String comparison: String identifiers are compared lexically (ASCII sort)
  6. Shorter < Longer: If all preceding identifiers are equal, the shorter set has lower precedence

Ordering Examples

From lowest to highest precedence:

1.0.0-alpha
1.0.0-alpha.1
1.0.0-alpha.beta
1.0.0-beta
1.0.0-beta.2
1.0.0-beta.11
1.0.0-rc.1
1.0.0

Why alpha.beta > alpha.1?

  • alpha vs alpha → equal
  • beta (string) vs 1 (numeric) → string > numeric

So 1.0.0-alpha.beta > 1.0.0-alpha.1.

Why beta.11 > beta.2?

  • beta vs beta → equal
  • 11 vs 2 → numeric comparison: 11 > 2

So 1.0.0-beta.11 > 1.0.0-beta.2. This is different from lexical string comparison where "11" < "2".

Pre-release in Ranges

An important npm behavior: a pre-release version only satisfies a range if the range explicitly includes a pre-release on the same major.minor.patch. For example, >=1.0.0-alpha.1 will include 1.0.0-alpha.2 but the general range >=1.0.0 will not match 1.0.1-alpha.1 in npm's implementation.

Use Case

Publishing alpha/beta/RC releases of npm packages and understanding how they will be resolved by consumers, or setting up CI pipelines that handle pre-release version channels.

Try It — Semver Calculator

Open full tool