npm: Why is a version “0.1” invalid?

Yes, this is required for semantic versioning, which is the versioning scheme npm packages use. Here’s the snippet from npm help json:

Version must be parseable by node-semver, which is bundled with npm as a dependency. (npm install semver to use it yourself.)

Here’s how npm’s semver implementation deviates from what’s on semver.org:

  • Versions can start with “v”
  • A numeric item separated from the main three-number version by a hyphen will be interpreted as a “build” number, and will increase the version. But, if the tag is not a number separated by a hyphen, then it’s treated as a pre-release tag, and is less than the version without a tag. So, 0.1.2-7 > 0.1.2-7-beta > 0.1.2-6 > 0.1.2 > 0.1.2beta

Leave a Comment