---
title: "Caret vs Tilde in package.json (^ vs ~) | Since.dev"
description: "Caret (^) allows minor and patch updates, tilde (~) only patches. The 0.x exception, what your lockfile does, and how ^ and ~ differ in Cargo and Composer."
canonical_url: https://since.dev/guides/caret-vs-tilde-package-json
last_updated: 2026-11-25
---

# Caret vs tilde in package.json: what ^ and \~ let in

In package.json, a caret (^1.2.3) accepts any 1.x release from 1.2.3 up, so new minor and patch versions, while a tilde (\~1.2.3) accepts only patch releases of 1.2. Below 1.0.0 the caret tightens: ^0.2.3 acts like \~0.2.3. Your lockfile decides what actually installs until you update it.

Updated November 25, 2026

## What's the difference between ^ and \~ in package.json?

The caret lets in new minor and patch releases; the tilde lets in patch releases only. Both are shorthand for a range, and npm's own [semver package](https://github.com/npm/node-semver) defines exactly what each one expands to. I asked it directly instead of trusting a cheat sheet:

```
$ cat ranges.js
const { Range } = require("semver")
for (const r of process.argv.slice(2))
  console.log(r.padEnd(8), new Range(r).range)

$ node ranges.js '^1.2.3' '~1.2.3' '^0.2.3' \
    '~0.2.3' '^0.0.3' '~1' '1.2.x'
^1.2.3   >=1.2.3 <2.0.0-0
~1.2.3   >=1.2.3 <1.3.0-0
^0.2.3   >=0.2.3 <0.3.0-0
~0.2.3   >=0.2.3 <0.3.0-0
^0.0.3   >=0.0.3 <0.0.4-0
~1       >=1.0.0 <2.0.0-0
1.2.x    >=1.2.0 <1.3.0-0
```

What npm reads each range as, from semver 7.8.6 on Nov 25, 2026

| You write | npm reads it as   | In plain words                    |
| --------- | ----------------- | --------------------------------- |
| ^1.2.3    | \>=1.2.3 <2.0.0-0 | Any 1.x from 1.2.3 up             |
| \~1.2.3   | \>=1.2.3 <1.3.0-0 | Any 1.2.x from 1.2.3 up           |
| ^0.2.3    | \>=0.2.3 <0.3.0-0 | 0.2.x only, the same as the tilde |
| ^0.0.3    | \>=0.0.3 <0.0.4-0 | 0.0.3 and nothing newer           |
| \~1       | \>=1.0.0 <2.0.0-0 | Any 1.x, the same as ^1           |
| 1.2.3     | 1.2.3             | Exactly 1.2.3                     |

The `-0` on each upper bound means the range also stops before pre-releases of the next version, so `^1.2.3` won't pick `2.0.0-rc.1`. The tilde's rule depends on how many numbers you write: `~1.2` is `>=1.2.0 <1.3.0-0`, but `~1` allows any 1.x, the same as a caret ([node-semver](https://github.com/npm/node-semver)).

## How do I see which versions a range actually allows?

Ask the registry. `npm view` accepts a range and prints every published version inside it ([npm docs](https://docs.npmjs.com/cli/v11/commands/npm-view)). Here's express on Nov 25, 2026:

```
$ npm view express@'~4.18.2' version
express@4.18.2 '4.18.2'
express@4.18.3 '4.18.3'

$ npm view express@'^4.18.2' version | tail -2
express@4.22.2 '4.22.2'
express@4.22.3 '4.22.3'
```

So the tilde stops at 4.18.3 and the caret goes all the way to 4.22.3. Neither reaches express 5, which was at 5.3.0 the same day. To test made-up versions against a range, the semver CLI prints the ones that match and drops the rest:

```
$ npx semver@7 -r '~1.2.3' 1.2.3 1.2.9 1.3.0
1.2.3
1.2.9

$ npx semver@7 -r '^1.2.3' 1.3.0-beta.1 1.9.0
1.9.0
```

The second run shows the pre-release rule: 1.3.0-beta.1 is inside the numbers, but a range only matches a pre-release when the range itself names one on the same major.minor.patch.

## Why does ^0.x act like \~?

Because before 1.0.0 every minor release is allowed to break you. SemVer item 4 says major version zero is for initial development and anything may change at any time ([semver.org](https://semver.org/)). npm's caret follows that: it never changes the left-most non-zero number, so on 0.x it treats the minor as the breaking digit, and on 0.0.x the patch.

```
$ npx semver@7 -r '^0.2.3' 0.2.3 0.2.9 0.3.0
0.2.3
0.2.9

$ npx semver@7 -r '^0.0.3' 0.0.3 0.0.4
0.0.3
```

A real case is esbuild, which is still on 0.x. A caret written a while ago doesn't move you far:

```
$ npm view esbuild@'^0.24.0' version
esbuild@0.24.0 '0.24.0'
esbuild@0.24.1 '0.24.1'
esbuild@0.24.2 '0.24.2'

$ npm view esbuild version
0.28.2
```

That's four minor versions behind, and `npm update` will never take you past 0.24.2. Moving to 0.28 is a deliberate change to package.json. And the tightened caret still isn't a promise: [esbuild's page on Since.dev](https://since.dev/packages/npm/esbuild), updated November 24, 2026, lists breaking changes recorded in the patch releases 0.28.1 and 0.28.2, which `^0.28.0` accepts.

## Why didn't npm install the newest version my caret allows?

Your lockfile. The range in package.json says what npm may pick; package-lock.json records what it did pick, and npm keeps that version for as long as it still fits the range. I installed express 4.18.2 (npm saved it as ^4.18.2), then reinstalled it three ways and asked which version landed each time (npm's own install messages left out):

```
$ npm install express@4.18.2
$ npm ls express | grep express@
`-- express@4.18.2

$ rm -rf node_modules && npm install
$ npm ls express | grep express@
`-- express@4.18.2

$ rm -rf node_modules && npm ci
$ npm ls express | grep express@
`-- express@4.18.2

$ rm -rf node_modules package-lock.json
$ npm install
$ npm ls express | grep express@
`-- express@4.22.3
```

Only deleting the lockfile let the caret do its job. In CI use `npm ci`: it installs exactly what the lockfile says, never writes to package.json or package-lock.json, and exits with an error if the two don't match ([npm docs](https://docs.npmjs.com/cli/v11/commands/npm-ci)).

To see the gap between what you have and what the range allows, run `npm outdated`. Its wanted column is the highest version that satisfies your range ([npm docs](https://docs.npmjs.com/cli/v11/commands/npm-outdated)). Then update within the range, install messages left out again:

```
$ npm outdated --json \
    | jq -c '.express | {current, wanted, latest}'
{"current":"4.18.2","wanted":"4.22.3","latest":"5.3.0"}

$ npm update express
$ npm ls express | grep express@
`-- express@4.22.3
$ grep '"express"' package.json
    "express": "^4.18.2"
```

`npm update` moved the lockfile and node_modules to 4.22.3 but left package.json at `^4.18.2`. That's the documented default; add `--save` if you want the range raised too ([npm docs](https://docs.npmjs.com/cli/v11/commands/npm-update)). Latest, 5.3.0, is outside the range, so no update command reaches it until you change the range yourself.

## How do I make npm save \~ or an exact version instead of ^?

Set `save-prefix` or use `--save-exact`. npm writes a caret by default because `save-prefix` defaults to `^` ([npm config docs](https://docs.npmjs.com/cli/v11/using-npm/config)):

```
$ npm config get save-prefix
^

$ npm install dotenv@16.6.1 --save-exact
$ npm install ms@2.1.2 --save-prefix='~'
$ grep -A4 '"dependencies"' package.json
  "dependencies": {
    "dotenv": "16.6.1",
    "express": "^4.18.2",
    "ms": "~2.1.2"
  }
```

To make it the project default, put `save-exact=true` or `save-prefix=~` in the project's .npmrc. It only changes what npm writes from then on; existing entries keep their prefix until you edit them or reinstall the package.

## Should I use caret, tilde or exact versions?

For most apps, keep the caret and commit the lockfile. The lockfile already pins every install, so the range only decides what an update is allowed to pick. Here's how I'd choose:

- Apps you deploy: caret, lockfile committed, `npm ci` in CI. Updates happen when you run them, on a branch, with tests.
- Libraries you publish: caret on your dependencies. Users install your package with their own lockfile, and a wide range lets npm share one copy of a dependency with the rest of their tree. An exact pin makes npm install a second copy whenever the app needs a different version.
- Tools whose output must match across the team: exact. Prettier's install guide asks for `--save-exact` because even a patch release can format code slightly differently ([Prettier docs](https://prettier.io/docs/install)).
- A package that has broken you in a minor release before: tilde, so the next minor is a choice you make on purpose.

Is the tilde safer? It lets in fewer releases, which is not the same thing. Many projects ship fixes, security fixes included, only on their newest minor line, and a tilde keeps you off it. Fewer surprises, more drift.

## Do ^ and \~ mean the same thing in Cargo, Composer, Poetry and pip?

Mostly the caret does, and the tilde doesn't. Each tool's docs, checked Nov 25, 2026:

Caret and tilde across package managers, from each tool's docs on Nov 25, 2026

| Tool                                                                                       | Caret, or the default             | Tilde, or the nearest operator             |
| ------------------------------------------------------------------------------------------ | --------------------------------- | ------------------------------------------ |
| [npm](https://github.com/npm/node-semver)                                                  | ^1.2.3 is >=1.2.3 <2.0.0          | \~1.2 is >=1.2.0 <1.3.0                    |
| [Cargo](https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html)            | A bare 1.2.3 already means ^1.2.3 | \~1.2 is >=1.2.0, <1.3.0                   |
| [Composer](https://getcomposer.org/doc/articles/versions.md)                               | ^1.2.3 is >=1.2.3 <2.0.0          | \~1.2 is >=1.2 <2.0.0, so new minors       |
| [Poetry](https://python-poetry.org/docs/dependency-specification/)                         | ^1.2.3 is >=1.2.3 <2.0.0          | \~1.2 is >=1.2.0 <1.3.0                    |
| [pip (PEP 440)](https://packaging.python.org/en/latest/specifications/version-specifiers/) | No caret                          | \~= 2.2 is >= 2.2, == 2.\*, so new minors  |
| [RubyGems and Bundler](https://guides.rubygems.org/versioning/)                            | No caret                          | \~> 2.2 is >= 2.2 and < 3.0, so new minors |

Two traps if you switch languages. First, Composer's `~1.2`, pip's `~= 2.2` and Ruby's `~> 2.2` all allow the next minor version, which npm's `~1.2` never does. In those three the last number you write is the one that's allowed to move, so `~1.2.3` in Composer is >=1.2.3 <1.3.0, like npm. Second, a bare version is exact in npm but a caret range in Cargo, so `serde = "1.0.100"` in Cargo.toml accepts any later 1.x.

## Does a caret range protect you from breaking changes?

Only as far as each maintainer keeps the SemVer promise. SemVer item 8 says incompatible changes need a new major version ([semver.org](https://semver.org/)), but nothing enforces it, and the RubyGems versioning guide points out that Ruby and Python both ship incompatible changes in minor releases ([RubyGems guide](https://guides.rubygems.org/versioning/)). A caret is a bet that the next minor is safe. Usually it is.

When you're about to move, the useful question isn't which symbol you wrote, it's what changed between your current version and the wanted one:

1. Run `npm outdated` and note current and wanted for each package.
2. Read what changed in between. Our guide to [finding the breaking changes between two versions](https://since.dev/guides/breaking-changes-between-versions.md) has the commands: list the releases, read each changelog, diff the published code.
3. Run `npm update` on a branch and let your tests decide.

## Where Since.dev fits

Since.dev can do step 2 for you. Its package pages list what each release removed, renamed or changed, with the source, and a coding agent can call `check_code` with a package and the version you're moving to. Give it a version, not a range: when I checked a package.json that held only `^4.18.2` and `^0.24.0`, it answered needs review for both, because no installed version was given, and asked for the lockfile or the package with its version. That's the right answer, since a range isn't a version. It reports what it finds and nothing merges or deploys. For keeping an eye on this across a whole project, see [how to track breaking changes in your dependencies](https://since.dev/guides/dependency-breaking-changes.md), or [scan a public repository](https://since.dev/scan.md) with no account.

## Questions

### What is the difference between tilde and caret in npm?

A caret (^1.2.3) allows any version from 1.2.3 up to, but not including, 2.0.0, so new minor and patch releases. A tilde (\~1.2.3) allows 1.2.3 up to, but not including, 1.3.0, so patch releases only. Below 1.0.0 the caret narrows: ^0.2.3 allows only 0.2.x.

### Why does npm add a caret when I install a package?

Because npm's save-prefix setting defaults to ^ ([npm config docs](https://docs.npmjs.com/cli/v11/using-npm/config)). Add `--save-exact` to npm install to write the exact version, or set save-prefix to \~ in .npmrc to write tildes.

### What does ^0.0.1 mean in package.json?

Only 0.0.1. The caret never changes the left-most non-zero number, and in 0.0.1 that's the patch, so the range runs from 0.0.1 up to, but not including, 0.0.2. Nothing newer is accepted until you change the range.

### Does package-lock.json override the caret?

In practice, yes. npm install keeps the version in the lockfile while it still satisfies the range, and npm ci installs exactly the lockfile. The caret only matters when you run npm update, add a package, or install without a lockfile.

### What do x and \* mean in a version range?

An x stands for any number in that position: 1.2.x means 1.2.0 up to, but not including, 1.3.0, like \~1.2, and 1.x means any 1.x release, like ^1. A bare \* or an empty string accepts any version, which is rarely what you want in an app.

### Is tilde safer than caret?

It's narrower, not safer. A tilde lets in fewer releases, so fewer surprises, but it also keeps you off newer minor lines where fixes, security fixes included, often ship first. Most apps do better with a caret, a committed lockfile and updates they run on purpose.

## Related guides

### Comparisons

- [Dependabot alternatives: what to use instead, and when](https://since.dev/guides/dependabot-alternative.md)Dependabot alternatives by job: other Git hosts, security scanners, malware blocking and breaking changes. Prices checked Nov 28, 2026, plus a real test.
- [eslint-plugin-import vs eslint-plugin-import-x: which should you use?](https://since.dev/guides/eslint-plugin-import-vs-import-x.md)eslint-plugin-import vs eslint-plugin-import-x, run on ESLint 10: which installs, which crashes, package exports, rules, dependencies and how to switch.

### How-to

- [How to find the breaking changes between two versions of a package](https://since.dev/guides/breaking-changes-between-versions.md)How to find breaking changes between two versions of a package: list the releases in between, read each changelog, diff the code. Commands for npm, PyPI, Go.
- [How to check your dependencies for breaking changes before you upgrade](https://since.dev/guides/dependency-breaking-changes.md)How to check dependencies for breaking changes before upgrading: the commands, a real failing upgrade, CI that fails on deprecations, and where notices appear.
- [Why PostCSS stopped loading your source map, and how to fix it](https://since.dev/guides/postcss-source-map-without-from.md)PostCSS 8.5.23 stopped loading source maps when opts.from is unset. Why your Sass map vanished, the one-line fix, and the two older rules that also drop maps.
- [python-multipart 0.0.20 to 0.0.34: what breaks when you upgrade](https://since.dev/guides/python-multipart-breaking-changes.md)Upgrading python-multipart from 0.0.20 to 0.0.34? Semicolons stop splitting form fields, Python 3.11 is the floor, and two APIs are gone. Tested side by side.

## Put your code on continuous maintenance.

Scan a public repository now, or give your agent one line.

[Scan a repository](https://since.dev/scan.md). Any public GitHub repository. No sign-in.

### Tell your agent what changed since it was trained.

`claude mcp add --transport http since https://api.since.dev/mcp`

[Get an API key](https://app.since.dev/login?mode=signup)

Codex, Cursor and any MCP client use https://api.since.dev/mcp.

---

Every page on this site as Markdown: https://since.dev/sitemap.md. For agents: https://since.dev/llms.txt.
