Illustrative Example: The Patch Release That Broke Everyone's Imports
This is an illustrative example, not a report about a real project. "Package A" is a small string-formatting library; every number below is an assumption chosen to make the arithmetic easy to follow. The point is to show how a change that felt like housekeeping ended up shipped under the wrong version number, and what it cost.
The setup (assumptions)
- Package A is at
3.4.1. Its README showsimport format from "package-a", a default export. - Assume roughly 40 downstream packages depend on it with a caret range such as
^3.4.0, the default thatnpm installwrites. - Maintainer B, tidying the code, converts the module to named exports only:
export { format, pad, truncate }. The tests are updated to match, so CI stays green. - Because "no new features were added", Maintainer B publishes the change as
3.4.2.
What happened next
A caret range accepts any later 3.x version, so every downstream project that runs a fresh install, or whose lockfile is regenerated, receives 3.4.2 automatically. Their code still says import format from "package-a". Depending on the bundler and module format, they now get either a build-time error about a missing default export or, worse, undefined at runtime when the first string is formatted.
Under the assumptions above, suppose a quarter of the 40 dependents rebuild within a day. That is ten broken builds, each producing an issue, and each of those projects in turn may have its own users who see a failure they cannot trace. The maintainer's own test suite never caught it because the tests were rewritten together with the code; they tested the new API, not the old contract.
Why it was a major change, not a patch
The semver.org specification defines a patch as a backward-compatible bug fix. Removing an export that the documentation told people to use is the textbook case of an incompatible change to the public API, which calls for a major bump. "I did not add anything" is the wrong test. The right test is "can any code that worked against 3.4.1 stop working against this version?" If the answer is yes, the version must be 4.0.0.
// 3.4.1 public surface
export default function format(s, opts) { ... }
// 3.4.2 public surface (default export gone)
export function format(s, opts) { ... }
export function pad(s, n) { ... }
The recovery, step by step
- Restore compatibility in a new patch. Publish
3.4.3that keeps the named exports and adds backexport default format. Users on caret ranges heal on their next install. - Deprecate the bad version.
npm deprecate package-a@3.4.2 "Removed the default export by mistake; upgrade to 3.4.3"shows a warning to anyone who still installs it. Deprecating is preferable to unpublishing, which npm restricts and which never frees the version number for reuse (see our note on unpublish policy). - Write an honest changelog line under Fixed for 3.4.3 explaining what 3.4.2 broke.
- Plan the real removal for 4.0.0, with a deprecation notice on the default export in a 3.x minor first.
What would have caught it
A single "contract" test that imports the package the way the README does, kept separate from the unit tests and never edited casually, would have failed immediately. So would an API-surface diff in CI that compares the exported names against the last published tarball. Both are cheap. Read semantic versioning explained for the version rules and testing the packed tarball for the second safeguard.