Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

9
  • 55
    It is also possible to specify an exact range of versions, like 1.2.0 || >=1.2.2 <1.3.0: Exactly 1.2.0, or everything from 1.2.2 to 1.3.0 (inclusive), but not 1.2.1, or 1.3.1 and above, and also not 1.1.x and below. Commented Jun 8, 2016 at 20:30
  • 1
    A more specific link form the above -> docs.npmjs.com/files/package.json#dependencies Commented Jul 11, 2018 at 12:38
  • 31
    "Approximately equivalent to version" and "Compatible with version" are such frustratingly non-specific ways to describe ~ and ^ behavior. Thank you @jgillich for providing an actual answer! Commented Jul 17, 2019 at 15:21
  • 1
    @Timo "deps that never depend on versions" probably don't exist. You can have deps that don't currently depend on versions, but future versions of the dependency are not guaranteed to be backwards compatible so unless you own the dependency as well as the application it's a safe bet that eventually 'latest' won't work. To me it seems the best use for a 'latest' specifier is during early development, proof-of-concepts, or for short term projects that will not be maintained long term. Commented Nov 17, 2021 at 14:11
  • 2
    @Simon_Weaver In that case, with a patch version of 0, yes they are equivalent. But if you had, for example, ~1.2.3, that's equivalent to >=1.2.3 <1.3.0, whereas 1.2.x would be equivalent to >=1.2.0 <1.3.0 --- essentially the ~ means any patch version greater than or equal to the one specified, whereas the x in that position means any number. Full syntax is defined here: github.com/npm/node-semver#advanced-range-syntax Commented Jul 6, 2023 at 2:02