npm's Unpublish Policy: What Changed After 2016 and What It Means Today
If you published a broken or embarrassing version to npm, your first instinct may be to delete it. On npm that is often not possible, and the reasons go back to a single incident in March 2016. This note gives the background and summarises how the current rules work, with the caveat that npm Docs is the authoritative source and the details have been revised over time.
The background: left-pad
In March 2016 a maintainer, after a dispute over a package name, unpublished all of his packages from npm. One of them was left-pad, a tiny string-padding function that a large number of other packages depended on, directly or through popular build tools. Installs began failing across the ecosystem until the package was restored. The incident showed that allowing unrestricted deletion of published code made every dependant vulnerable to one person's decision, and npm changed its policy shortly afterwards.
How the rules work now, in outline
- Shortly after publishing, within a 72-hour window, you can unpublish a version or package, provided no other public packages in the registry depend on it.
- After that window, unpublishing is allowed only when a set of conditions are all met: broadly, no other public packages depend on it, it has had low recent download activity, and it has a single owner or maintainer. npm Docs states the exact thresholds.
- Versions are never reused. Once
name@1.2.3has been published, that exact version can never be published again, even after unpublishing. You must publish a new version number. - Whole-package unpublish also blocks republishing under that name for a period, which prevents someone else from immediately grabbing the freed name.
- If you cannot unpublish, npm support can help in special cases such as accidentally published secrets or legal problems.
The usual right answer: deprecate and release
In almost every case, you do not need to unpublish. You need to stop people installing the bad version, which deprecation and a new release achieve without breaking anyone who already pinned it:
# mark the bad version
npm deprecate my-lib@1.4.1 "Broken build, use 1.4.2"
# publish the fix
npm version patch && npm publish
# if 1.4.1 was tagged latest, make sure latest now points at 1.4.2
npm dist-tag ls my-lib
Deprecation prints a warning whenever someone installs the version, and new installs using a range will resolve to the fixed release. If you leaked a secret in the tarball, rotate the secret first: assume it is already copied, whatever happens to the package.
Comparison with other registries
Other ecosystems reached similar conclusions by different routes. PyPI and crates.io offer yanking, which hides a release from new resolution while keeping it downloadable for exact pins; Python's yanking is defined in PEP 592. Go uses retract directives in go.mod because the module proxy and checksum database keep versions permanently. The shared principle is that published versions should be immutable, and that the fix for a bad release is a better release. Our notes on deprecation warnings cover the in-code side.