Search code examples
npmsemantic-versioning

Why does this `npm version` command break?


Quite simply, this command works:

npm version 0.13.0-20190723T144221.855f01d

But this one doesn't:

npm version 0.13.0-20190723T125957.0665893

Why? It broke our build process, so it would be useful to understand why this occurred.


Solution

  • None of the parts behind the hyphen are allowed to be numbers that have a leading 0 (unless the number equals 0).

    This only applies to numbers, making both .855f01d and .0855f01d valid, but .0855 is not valid.

    This can be found in Rule 9 of https://semver.org/spec/v2.0.0.html:

    A pre-release version MAY be denoted by appending a hyphen and a series of dot separated identifiers immediately following the patch version.

    Identifiers MUST comprise only ASCII alphanumerics and hyphen [0-9A-Za-z-]. Identifiers MUST NOT be empty.

    Numeric identifiers MUST NOT include leading zeroes.

    For testing purposes, you can fill in your proposed or attempted Version on this page: https://jubianchi.github.io/semver-check/#/ .