Skip to content

Instantly share code, notes, and snippets.

@zach2825
Last active August 15, 2025 13:35
Show Gist options
  • Save zach2825/db86321fa426e70cad1c828fdc709805 to your computer and use it in GitHub Desktop.
Save zach2825/db86321fa426e70cad1c828fdc709805 to your computer and use it in GitHub Desktop.
package-update patterns

In package.json, those symbols (~, ^, *) are version range specifiers for npm/yarn/pnpm, and they control how dependency updates are allowed when you run install or update.

Here’s the breakdown:


^ (caret)Allow non-breaking updates

  • Means “install the latest minor/patch version, but don’t bump the major version.”

  • Example:

    "lodash": "^4.17.21"

    → Can install anything from 4.17.21 up to <5.0.0.

  • Good default for most libraries following semver.


~ (tilde)Allow patch updates only

  • Means “stick to this minor version, but allow patches.”

  • Example:

    "lodash": "~4.17.21"

    → Can install 4.17.22, 4.17.23, etc., but not 4.18.0.

  • Use when you want more stability, but still get bug fixes.


* (wildcard)Allow any version

  • Means “any version is fine.”

  • Example:

    "lodash": "*"

    → Will install the latest available version, even major bumps.

  • Very risky — rarely used outside internal tools or prototyping.


Other related patterns

  • Exact version:

    "lodash": "4.17.21"

    → Only ever installs that exact version.

  • Ranges:

    "lodash": ">=4.17.0 <5.0.0"

    → Explicit range control.

  • X ranges:

    "lodash": "4.17.x"

    → Any patch in 4.17.

  • Latest:

    "lodash": "latest"

    → Always grabs newest published version.


Rule of thumb:

  • Use ^ for libraries where minor updates are safe.
  • Use ~ for more stability-sensitive code.
  • Avoid * in production unless you love surprise breakages.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment