With npm, `[email protected]` went out broken twenty minutes ago — what do `npm unpublish` and the registry's unpublish policy allow, and why must the fix still ship as 2.4.2?
answer
- the registry decides, not the CLI
- whose 72 hours: the package's
- dependents block it in every case
- downloads and owners after the window
- a name@version is spent forever
basics
~20 sThe registry lets npm unpublish [email protected] through only with no public dependents and, unless the package itself is under 72 hours old, under 300 weekly downloads and one owner. 2.4.1 can never be reused, so the fix ships as 2.4.2.
solid answer
~50 sThe public registry's policy decides, not the CLI. A **newly created package** can be unpublished within **72 hours** of its initial publish if no other package in the public registry depends on it. At any other time, unpublishing needs all three of: **no public dependents**, **fewer than 300 downloads** over the last week and a **single owner**. Twenty minutes since 2.4.1 is not twenty minutes since the package was created, so an established date picker is judged by the three conditions. The command takes exactly one version, `npm unpublish [email protected]`; ranges and tags are refused, and removing every version needs `--force` and blocks new versions for **24 hours**. Either way, `[email protected]` can **never be reused**, so the fix is `2.4.2`. Move the label first with `npm dist-tag add [email protected] latest`; if the unpublish is refused, `npm deprecate [email protected] "…"` attaches a warning instead.
code
bash · 12 lines# 1. new bare installs get the last good version again
npm dist-tag add [email protected] latest
# 2. remove the broken version (only if the registry policy allows it)
npm unpublish [email protected]
# 2b. if the registry refuses, mark it instead
npm deprecate [email protected] "Broken keyboard focus; upgrade to 2.4.2"
# 3. the fix needs a new number; publish moves latest to it
npm version patch
npm publishgo deeper
Recall that a published version number can never be reused, so a fix always goes out as a new version.
Explain the policy: a new package within 72 hours of its initial publish needs no public dependents; otherwise also under 300 weekly downloads and a single owner.
Sequence the incident: move latest back with npm dist-tag add, unpublish if the registry allows it or deprecate the exact version, then publish 2.4.2.
Weigh what an unpublish breaks for lockfiles that already resolved the version, and keep a release runbook so nobody improvises these steps under pressure.
## The registry's rule, not the CLI's `npm unpublish` sends a request; the **public registry's unpublish policy** decides whether it succeeds. The policy starts from one principle — registry data is immutable, so once `[email protected]` exists, no package can ever be published again as `[email protected]` — and then allows removal in two cases: | Case | Unpublish allowed when | |---|---| | A newly created package, within 72 hours of its initial publish | No other package in the public registry depends on it | | Any package, however long ago it was published | No public dependents **and** fewer than 300 downloads over the last week **and** a single owner or maintainer | The trap in this scenario is the clock. The 72-hour window, as the policy and the registry docs word it, belongs to a **newly created package** and counts from its **initial publish**. `a11y-datepicker` has existed since its 1.x days; only version 2.4.1 is twenty minutes old. So the second row applies: if any public package depends on the date picker, if it had 300 or more downloads last week, or if it has more than one owner, the registry refuses the unpublish. A brand-new package published by mistake twenty minutes ago is the case the first row was written for. ## What the `npm unpublish` command accepts The CLI adds its own guard rails on top of the policy: - **Exactly one version.** `npm unpublish [email protected]` removes that version and its tarball. A range such as `@2.4.x` or a tag such as `@latest` is refused: *"Can only unpublish a single version, or the entire project. Tags and ranges are not supported."* - **No argument** means the name and version in the current folder's `package.json` — easy to run by accident in the wrong checkout. - **The whole package** (`npm unpublish a11y-datepicker --force`) removes every version and the package entry; without `--force` npm refuses with "Refusing to delete entire project". - **The last remaining version** is treated the same way: npm refuses without `--force`, because removing it removes the package. - After a package is **entirely** unpublished, no new version of it can be published for **24 hours**. ## Why 2.4.1 can never come back A published `name@version` is spent permanently. `npm publish` refuses a version that already exists, and the registry refuses one that existed and was unpublished. So "unpublish 2.4.1, fix the bug, publish 2.4.1 again" is impossible: the fix must carry a new number, `2.4.2`. The rule protects consumers — a lockfile entry for `[email protected]` with its integrity hash can never silently point at different code. Immutability has a cost when an unpublish does succeed: a project whose lockfile already resolved 2.4.1 in those twenty minutes now asks for a tarball that no longer exists, so its next clean install fails unless the tarball is still in that machine's local cache. ## A twenty-minute incident, in order 1. **Move the label.** `npm dist-tag add [email protected] latest` — from now on a bare `npm install a11y-datepicker` gets the last good version. This works whatever the policy says about unpublishing. 2. **Remove or mark the bad version.** Try `npm unpublish [email protected]`. If the registry refuses, run `npm deprecate [email protected] "Broken keyboard focus; upgrade to 2.4.2"` so every install of it prints the warning. 3. **Ship the fix as a new number.** Bump to `2.4.2` and run `npm publish`. It is higher than every published stable version, so the publish moves `latest` to it. 4. **Check the result.** `npm dist-tag ls a11y-datepicker` confirms where `latest` points; the 2.4.1 deprecation can stay as a record. ## How `npm deprecate` behaves `npm deprecate <pkg>@<range> "<message>"` changes the registry entry, not the tarball: matching versions stay installable and print the message when installed. It accepts **ranges**, and those ranges **include prereleases** — `npm deprecate a11y-datepicker@"2.4.x" "…"` would also mark the good 2.4.0, and `@3.x` would catch `3.0.0-beta.1`. An empty message, `""`, removes the deprecation, as does `npm undeprecate`. You must be an owner of the package to run either. The interview answer: the window and its conditions come from the registry and the 72 hours are the package's, the CLI takes one exact version, and a version number is gone for good — so a fix is always a new release.
- Why is `npm deprecate a11y-datepicker@"2.4.x" "broken"` the wrong command here, and how do you undo it?The range matches every 2.4 version, including the good 2.4.0 and any 2.4 prerelease, because deprecate ranges include prereleases. Deprecate the exact version, `[email protected]`, instead. To undo a deprecation, run `npm deprecate` on the same spec with an empty message, `""`, or use `npm undeprecate`.
- A brand-new package, published by mistake twenty minutes ago with one version, has to go. What do the npm rules allow?This is the case the 72-hour window covers: with no public dependents it can be unpublished. Because it is the only version, npm refuses without `--force`; with it, the package entry goes, no new version of that name can be published for 24 hours, and the removed version number can never be reused.
- Unpublish 2.4.1, fix it, and publish 2.4.1 again
- A version published twenty minutes ago can always be unpublished
- npm unpublish [email protected] removes the whole minor line
- Deprecating 2.4.1 deletes its tarball from the registry
- Unpublishing a version breaks no one who already locked it
- Moving latest back to 2.4.0 needs a republish of 2.4.0