Semantic version ranges and upgrade decisions
Quick answer
Semantic version ranges describe acceptable releases, not the exact version installed. npm uses node-semver range rules to select matching versions.
Tooling examples
Use a separate CommonJS project with a reviewed exact version of semver installed. The local evidence uses npm’s bundled node-semver, not an installation from a registry. Local check available; consult validation evidence for what was asserted.
// Requires the semver package installed in the project.const semver = require("semver");console.log(semver.satisfies("1.9.0", "^1.2.3"), semver.satisfies("2.0.0", "^1.2.3"));Expected observation: true false
Use a separate CommonJS project with a reviewed exact version of semver installed. The local evidence uses npm’s bundled node-semver, not an installation from a registry. Local check available; consult validation evidence for what was asserted.
const semver = require("semver");console.log(semver.satisfies("0.2.9", "^0.2.3"), semver.satisfies("0.3.0", "^0.2.3"));Expected observation: true false
How the tooling works
For ordinary stable versions, ^1.2.3 allows versions from 1.2.3 up to but excluding 2.0.0; ~1.2.3 stops before 1.3.0. Caret ranges below 1.0.0 are narrower: ^0.2.3 stops before 0.3.0, and ^0.0.3 stops before 0.0.4. Prereleases have additional matching rules. An exact version is not a promise that the package is secure or compatible; test updates and review release notes. The lockfile captures the selected dependency tree.
Common mistakes
Do not compare version strings lexicographically or assume ^ permits every 0.x version.
Practice
Predict whether 1.9.0, 2.0.0, 0.2.9 and 0.3.0 match the two caret ranges in the examples; then confirm with an installed semver library.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Semantic version ranges and upgrade decisions — Knowledge Check
Assess tooling contracts, diagnostic reasoning and transfer to a project.
Which stable version satisfies ~1.2.3?
What does ^0.0.3 allow among these stable releases?
What records the actual resolved tree for a project?
In Semantic version ranges and upgrade decisions, what is the expected observation for example 1 in its documented setup? // Requires the semver package installed in the project. const semver = require("semver"); console.log(semver.satisfies("1.9.0", "^1.2.3"), semver.satisfies("2.0.0", "^1.2.3"));
In Semantic version ranges and upgrade decisions, what is the expected observation for example 2 in its documented setup? const semver = require("semver"); console.log(semver.satisfies("0.2.9", "^0.2.3"), semver.satisfies("0.3.0", "^0.2.3"));