Dependency types and version ranges
Local practice: Node.js 22.16.0 and npm 10.9.2 on Linux x64; proposed teaching baseline 26.13.1 LTS remains untested. Use a fresh disposable folder for each example, copy only the shown files and run the fixed command. No packages or external services required. Static examples are not ByteMind runner support. The archive is author-only; do not copy expected.json into the example directory.
Inspect dependency roles
const manifest = { dependencies: { "demo-parser": "^1.2.3" }, devDependencies: { "demo-format": "~2.1.0" }, peerDependencies: { "demo-host": "^3.0.0" } };for (const role of Object.keys(manifest)) console.log(role, Object.keys(manifest[role])[0]);Run in this fixture directory:
node main.mjsExpected stdout:
dependencies demo-parserdevDependencies demo-formatpeerDependencies demo-hostExpected exit status: 0. Expected stderr: empty. Each declaration has a role independent of its version range.
How it works
dependencies usually contains runtime requirements, devDependencies development tools, peerDependencies compatibility requirements on a consuming project (npm 7+ can install peers automatically), and optionalDependencies packages whose failed installation may be tolerated. In ordinary stable SemVer, 1.2.3 is exact, ^1.2.3 allows releases from 1.2.3 up to but not including 2.0.0, and ~1.2.3 stops before 1.3.0. Caret rules are narrower for zero-major releases: ^0.2.3 stops before 0.3.0. Pre-release matching has extra rules. The names below are fictional; do not install them. The sample evaluates a restricted stable-version interval, not a replacement for npm semver.
Compare stable release candidates
function acceptsCaret123([major, minor, patch]) { return major === 1 && (minor > 2 || (minor === 2 && patch >= 3));}for (const version of [[1,2,2],[1,2,3],[1,9,0],[2,0,0]]) { console.log(version.join("."), acceptsCaret123(version));}Run in this fixture directory:
node main.mjsExpected stdout:
1.2.2 false1.2.3 true1.9.0 true2.0.0 falseExpected exit status: 0. Expected stderr: empty. This deliberately restricted function compares nonnegative integer tuples for the single range ^1.2.3; it does not parse arbitrary npm ranges.
Common mistake
Do not assume every caret range permits all releases until the next major version. Do not equate compatible version numbers with proven compatibility or security.
Try it yourself
For a package at 0.2.3, compare 0.2.9 and 0.3.0 against the caret range. Then explain which dependency field you would use for a development-only formatter.
Further reading: Official documentation 1. Related ByteMind reference candidate: node-npm-dependency-ranges (route not verified).
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Dependency types and version ranges — knowledge check
Apply the concepts and predict the behavior taught in this lesson.
Where does a development-only formatter normally belong?
Which stable version satisfies ^1.2.3?
What is the upper exclusive bound of ^0.2.3?