npm publish "409 Conflict - cannot publish over previously published version" in CI
The version in package.json already exists on the registry, and npm never lets you overwrite a published version. The fix is to bump the version, not to force the publish.
What this error means
npm publish fails with "npm ERR! code E409" and "409 Conflict - PUT https://registry.npmjs.org/<pkg> - You cannot publish over the previously published versions: <version>."
npm ERR! code E409
npm ERR! 409 Conflict - PUT https://registry.npmjs.org/my-pkg - You cannot publish over the previously published versions: 1.4.2.Common causes
The version was never bumped before publishing
CI ran npm publish with a package.json version that is already live. npm treats published versions as immutable and rejects the re-publish.
A re-run of a release job that already succeeded
A retried or duplicated release workflow publishes the same tag twice; the first succeeded, the second hits 409.
How to fix it
Bump the version before publishing
- Increment the version in package.json (or run
npm version patch). - Commit and tag the new version as part of the release.
- Re-run the publish so it targets a version that does not exist yet.
npm version patch -m "release %s"
npm publishMake CI publish idempotent
Guard the publish step so a re-run does not try to republish an existing version. A common pattern checks the registry for the version first.
- run: |
V=$(node -p "require('./package.json').version")
if npm view "$(node -p "require('./package.json').name")@$V" version >/dev/null 2>&1; then
echo "already published, skipping"
else
npm publish
fiHow to prevent it
- Only publish from a tagged release that always carries a fresh version.
- Use
npm versionto bump and tag in one step. - Add a guard so re-running a release job skips an already-published version.