npm "409 Conflict" on Publish - Fix Duplicate/Concurrent Publish in CI
A 409 Conflict on publish means the registry rejected the PUT because it conflicts with current state - almost always the version already exists, or two release jobs tried to publish it at the same moment.
What this error means
npm publish fails with E409 409 Conflict - PUT. The release pipeline may have re-run, or two parallel jobs raced; either way the registry refuses to create a version that conflicts with what is already there.
npm error code E409
npm error 409 Conflict - PUT https://registry.npmjs.org/@acme%2fpkg
npm error Conflict: version 2.3.0 already existsCommon causes
The version already exists
A re-run of the release job tries to publish a version that a previous run already published. Registries are immutable, so the duplicate PUT conflicts.
Two release jobs published concurrently
Parallel pipelines (e.g. a matrix or a duplicate trigger) race to publish the same version, and one loses with a 409.
How to fix it
Guard publish to a new, single version
Only publish when the version is not already on the registry, and serialize the release job.
VER=$(node -p "require('./package.json').version")
if npm view "@acme/pkg@$VER" version >/dev/null 2>&1; then
echo "already published; skipping"
else
npm publish
fiSerialize and de-duplicate releases
- Use a concurrency guard so only one release job runs at a time.
- Bump the version before publishing so each run targets a new one.
- Make the publish step idempotent (skip-if-exists).
How to prevent it
- Run publish from one serialized release job.
- Skip publish when the version already exists.
- Bump the version on every release.