Exact Pins or Version Ranges? The Library Dependency Debate
Applications and libraries are different animals, and much of the arguing about dependency versions comes from forgetting that. An application controls its whole install; a library is one guest in somebody else's tree. This page lays out the two main positions on how a library should declare its own dependencies, then where they actually disagree.
The case for ranges
The mainstream advice in both the npm and Python packaging communities is that a library should declare the widest range it genuinely supports. In package.json that usually means a caret range; in pyproject.toml a lower bound and sometimes an upper one:
// package.json
"dependencies": { "yaml-core": "^2.3.0" }
# pyproject.toml
dependencies = ["yaml-core>=2.3"]
The reasoning is about the consumer. If your library pins yaml-core at exactly 2.3.0 and another library in the same app pins 2.3.4, npm may install two copies, which bloats bundles and can break instanceof checks. In Python the situation is stricter: pip installs one version per environment, so two incompatible pins simply fail to resolve. Ranges let the consumer's resolver find a single version that satisfies everyone, and let security patches flow in without waiting for you to release.
The case for exact pins
The other camp has been burned. A dependency ships a patch release that is accidentally breaking, or a compromised maintainer account publishes a malicious version, and every library with an open range pulls it in on the next fresh install. Pinning exactly means your users get the combination you tested and nothing else. Some maintainers of command-line tools, which behave more like applications than libraries, pin for exactly this reason.
Pin advocates also point out that a range is a promise you cannot verify. Declaring ^2.3.0 claims compatibility with versions that do not exist yet.
Where the disagreement really lies
| Question | Ranges view | Pins view |
|---|---|---|
| Who should control the final versions? | The application, through its lockfile | The library author, who tested them |
| How should security fixes arrive? | Automatically, within the range | Through a deliberate new release |
| Main risk accepted | An upstream release breaking users | Duplicate copies or unresolvable trees |
| Typical fit | Libraries imported by other code | Standalone CLIs and apps |
Most of the conflict dissolves once you notice that lockfiles exist for the pinning job. An application's package-lock.json, poetry.lock or uv.lock records exact versions for that one install, while the library's manifest says what is allowed. Note that npm does not use a dependency's own lockfile when it is installed as a dependency, so a library's lockfile only pins your development and CI environment.
A middle path many maintainers take
- Declare ranges in the published manifest, starting from the oldest version you actually test.
- Commit a lockfile for your own CI so builds are reproducible.
- Run a scheduled CI job against the newest versions in range, so you learn about upstream breakage before your users do.
- Add an upper bound only when you know a future major will break you, not as a reflex.
Neither side is foolish. The useful question for your package is whether it is a component or a finished tool. For background on how caret and tilde ranges are interpreted, see our semantic versioning guide.