Skip to content

Menu

Semver Cheat Sheet: Version Ranges, Caret, Tilde and Pre-releases

Checked against Semantic Versioning SemVer 2.0.0 spec; node-semver 7.8.6 (every range run locally) on 28 November 2026. Each section links to the official docs it was checked against.

Use this sheet when you need to know exactly which versions a range in package.json will accept. It covers the Semantic Versioning 2.0.0 spec and the range syntax of node-semver 7.8.6, the library npm uses. Every range and comparison below was run through semver 7.8.6 in Node, and the expanded ranges shown are what the library printed.

When to use what

A caret (^1.2.3) is the npm default and the right choice for most libraries that follow semver: you get bug fixes and new features but never a new major. A tilde (~1.2.3) only takes patch releases, which is what I use for packages that have broken me in a minor release before. An exact pin (1.2.3) belongs in applications where you want every upgrade to be a reviewed pull request, although the lockfile already gives you that for installs.

Be careful below 1.0.0. The spec says anything may change in a 0.x release, and node-semver's caret reflects that: ^0.2.3 stops before 0.3.0, and ^0.0.3 accepts only 0.0.3 itself. So a caret on a 0.x package behaves like a tilde or a pin.

Pre-releases are opt-in. A range only matches a pre-release such as 1.3.0-beta.1 if the range itself names a pre-release on the same major.minor.patch, or if you pass includePrerelease. That keeps betas out of normal installs. To try ranges live, use the semver calculator, and to order two versions use the semver comparator. The longer post on semver and npm ranges has more background.

Precedence compares major, minor and patch as numbers, then pre-release identifiers one by one: numeric identifiers compare as numbers, alphanumeric ones in ASCII order, and a shorter set of identifiers is lower when all earlier ones are equal. Build metadata after + is ignored.

MAJOR.MINOR.PATCH

Bump MAJOR for incompatible API changes, MINOR for compatible features, PATCH for compatible bug fixes

1.0.0-alpha.1

Pre-release: a hyphen and dot-separated identifiers; it ranks below 1.0.0

1.0.0+build.5

Build metadata after a plus sign; it doesn't affect precedence, so 1.0.0+build.5 satisfies 1.0.0

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

The ordering semver.sort() returned; note beta.11 sorts after beta.2 because numeric parts compare as numbers

0.y.z

Initial development: the spec says the public API shouldn't be considered stable

Right-hand values are the output of semver.validRange() in 7.8.6. The -0 suffix on an upper bound keeps pre-releases of the next version out of the range.

^1.2.3

Expands to >=1.2.3 <2.0.0-0: anything up to the next major

~1.2.3

Expands to >=1.2.3 <1.3.0-0: patch releases only

~1

Expands to >=1.0.0 <2.0.0-0; with only a major, tilde allows minor bumps

1.2.x

X-range: >=1.2.0 <1.3.0-0 (1.2.* and 1.2 mean the same)

*

Any version; the expanded form is still *

1.2.3 - 2.3.4

Inclusive hyphen range: >=1.2.3 <=2.3.4

1.2 - 2.3

A partial upper bound is filled out: >=1.2.0 <2.4.0-0, so 2.3.5 matches

>=1.2.7 <1.3.0

Space means AND: both comparators must match

1.2.7 || >=1.2.9 <2.0.0

|| means OR: 1.2.7 exactly, or anything from 1.2.9 below 2.0.0

The caret allows changes that don't modify the left-most non-zero part. Below 1.0.0 that part is the minor or the patch.

^0.2.3

Expands to >=0.2.3 <0.3.0-0: 0.2.9 matches, 0.3.0 does not

^0.0.3

Expands to >=0.0.3 <0.0.4-0: effectively an exact pin

^0.x

Expands to <1.0.0-0: any 0.x release

^1.x

Expands to >=1.0.0 <2.0.0-0, same as ^1.0.0

>1.2.3-alpha.3

Matches 1.2.3-alpha.7 and 3.4.5, but not 3.4.5-alpha.9 (pre-release on a different version)

^1.2.3-beta.2

Expands to >=1.2.3-beta.2 <2.0.0-0; later 1.2.3 pre-releases match, other versions' pre-releases don't

satisfies('1.3.0-beta.1', '^1.2.3')

Returns false: plain ranges skip pre-releases

satisfies('1.3.0-beta.1', '^1.2.3', { includePrerelease: true })

Returns true once you opt in

npx semver -r '>=1.0.0' 1.5.0-beta.1

Prints nothing and exits with status 1

npx semver -p -r '>=1.0.0' 1.5.0-beta.1

Prints 1.5.0-beta.1: -p is --include-prerelease

npm version is documented at https://docs.npmjs.com/cli/v12/commands/npm-version. Outputs here are from semver 7.8.6 and npm 11.4.2.

npx semver -r '^1.2.0' 1.1.9 1.2.5 1.9.0 2.0.0

Print the versions that fit a range; here 1.2.5 and 1.9.0

npx semver -i prerelease --preid rc 1.4.0

Increment to a pre-release; prints 1.4.1-rc.0

semver.inc('1.2.3', 'premajor', 'beta')

Returns 2.0.0-beta.0

semver.inc('1.2.3-rc.1', 'patch')

Returns 1.2.3: a patch bump on a pre-release just drops the tag

semver.maxSatisfying(['1.2.3','1.4.0','2.0.0'], '^1.2.0')

Returns 1.4.0, the highest version in range

semver.coerce('v3.4 final')

Pulls a version out of loose text; returns 3.4.0

semver.diff('1.2.3', '1.3.0')

Returns minor, the kind of change between two versions

npm version prerelease --preid=beta

Bump package.json from 1.0.1 to 1.0.2-beta.0 (add --no-git-tag-version to skip the commit and tag)

Worked example: Work out why a beta isn't being installed

A teammate published 1.3.0-beta.1 of your shared library and asks why the app with "lib": "^1.2.3" doesn't pick it up. Check the range the way npm's resolver sees it:

> semver.validRange('^1.2.3')
'>=1.2.3 <2.0.0-0'
> semver.satisfies('1.3.0-beta.1', '^1.2.3')
false
> semver.satisfies('1.3.0-beta.1', '^1.2.3', { includePrerelease: true })
true
> semver.validRange('^1.3.0-beta.0')
'>=1.3.0-beta.0 <2.0.0-0'

The version is numerically inside the range, but node-semver leaves pre-releases out unless the range mentions a pre-release on the same 1.3.0 tuple. You have two clean options. To test the beta in one app, change the range to ^1.3.0-beta.0; that admits 1.3.0 betas now and keeps accepting 1.3.0 and later 1.x releases after the final ships. Or install the exact version with npm install [email protected]. Don't turn on include-prerelease globally, because then every range in the project starts matching every beta on the registry.

Common mistakes

  • Assuming ^0.4.1 will pick up 0.5.0

    Below 1.0.0 the caret locks the minor, so it stops at 0.4.x. Bump the range by hand when you're ready for 0.5.

  • Sorting versions as strings, which puts 1.10.0 before 1.9.0 and beta.11 before beta.2

    Use semver.sort() or semver.compare(); they compare numeric parts as numbers, as the spec requires.

  • Putting build info such as a commit hash in the pre-release part, like 1.2.0-abc123

    Pre-release identifiers change precedence and range matching. Put build data after +, as in 1.2.0+abc123, where it is ignored.

  • Writing 1.2 - 2.3 and expecting 2.3.5 to be excluded

    A partial upper bound in a hyphen range becomes <2.4.0-0. Write 1.2.0 - 2.3.0 if you mean an exact ceiling.

  • Writing >=1.0.0, <2.0.0 with a comma as in Python specifiers

    node-semver joins comparators with a space for AND and || for OR: >=1.0.0 <2.0.0.

Sources

How we research: where our facts come from, how often we re-check them, and why no one can pay for a review or a verdict.

What changed in AI dev tools, once a month

Renames, shutdowns, pricing changes and new MCP setups, each with a source.

Subscribe
Reviews and commentsShow

Comments

Sign in to leave a comment.

Loading comments…