DEV Community

TheOmniKit
TheOmniKit

Posted on

TIL ^0.2.3 will not let in 0.3.0

til, and it's a small thing but it would have bitten me. ^1.2.3 means anything below 2.0.0, everybody knows that. but ^0.2.3 does NOT mean below 1.0.0. it means at least 0.2.3 and below 0.3.0. so 0.2.9 is fine and 0.3.0 is not.

reason is that under 1.0.0 npm treats the first non-zero number as the "major", because the API isn't stable yet. so ^0.0.3 allows only 0.0.3, nothing else. you move the package to 1.0.0 and only then the wide caret range switches on.

tilde is simpler, ~1.2.3 takes 1.2.4 and 1.2.10 but not 1.3.0.

other one that people get wrong, 1.10.0 is newer than 1.9.0, each part is a whole number. and 2.0.0-rc.1 is older than 2.0.0.

i made a small checker for this on my site, you type a range, paste versions one per line and it says which are inside and sorts them properly. i built this one so ya, i'm biased, but just try ^0.2.3 once and see: https://theomnikit.com/dev/semver-checker?utm_source=devto&utm_medium=article&utm_campaign=devto-caret-zero-versions

(AI helped me tidy this post, the facts are from the semver spec and node-semver docs.)

Top comments (0)