What is the difference between ~ and ^ in package.json?

← Node.js answers

^1.4.2 accepts any 1.x.y version at or above 1.4.2, while ~1.4.2 accepts only 1.4.y patch updates.

  • ^1.4.2 matches >=1.4.2 and <2.0.0 (new features and fixes, no breaking changes).
  • ~1.4.2 matches >=1.4.2 and <1.5.0 (bug fixes only).
  • 1.4.2 matches exactly that version.
  • For 0.x versions the caret is stricter: ^0.4.2 matches >=0.4.2 and <0.5.0.

npm install writes a caret by default. The lock file (package-lock.json) is what actually fixes the versions that get installed, so commit it and use npm ci in CI for reproducible builds.

Related questions

Start debugging smarter today

Try Bugsee for free — no commitments, no hidden fees.

Free sign upLive demoNo credit card required