theonedev/onedev · error · ClientException
Package already exists (name: %s, version: %s)
Error message
Package already exists (name: %s, version: %s)
What it means
On npm publish, before creating a new Pack the handler checks findByNameAndVersion. If a pack with the same name and version already exists AND its file blob still exists in storage, the publish is rejected with HTTP 409 Conflict 'Package already exists (name: %s, version: %s)'. npm forbids overwriting published versions.
Source
Thrown at server-plugin/server-plugin-pack-npm/src/main/java/io/onedev/server/plugin/pack/npm/NpmPackHandler.java:402
byte[] packageMetadataBytes = writeJson(packageMetadata);
if (versionsNode != null) {
for (var it = versionsNode.fields(); it.hasNext(); ) {
var field = it.next();
var version = field.getKey();
var versionMetadata = (ObjectNode) field.getValue();
var name = versionMetadata.get("name").asText();
LockUtils.run(getLockName(projectId, name), () -> {
transactionService.run(() -> {
var project = projectService.load(projectId);
var pack = packService.findByNameAndVersion(project, TYPE, name, version);
if (pack != null) {
var packData = (NpmData) pack.getData();
if (packBlobService.checkPackBlob(projectId, packData.getFileSha256BlobHash()) != null) {
var errorMessage = String.format("Package already exists (name: %s, version: %s)",
name, version);
throw new ClientException(SC_CONFLICT, errorMessage);
}
} else {
pack = new Pack();
pack.setType(TYPE);
pack.setName(name);
pack.setVersion(version);
pack.setProject(project);
}
Build build = null;
if (buildId != null)
build = buildService.load(buildId);
pack.setBuild(build);
pack.setUser(SecurityUtils.getUser());
pack.setPublishDate(new Date());
var distTagsOfVersion = new LinkedHashSet<String>();
for (var entry : distTags.entrySet()) {
if (entry.getValue().equals(version))View on GitHub (pinned to d44925c47c)
Solutions
- Bump the version in package.json and publish again (npm requires unique versions)
- If the existing pack is unwanted, delete that package version from the OneDev project UI then republish
- Make CI publish steps conditional/idempotent so they skip when the version already exists
- Note: if the blob was missing (checkPackBlob returned null) the handler re-creates instead — this error means the data is fully intact
Example fix
// before "version": "1.0.0" // already published // after "version": "1.0.1"
Defensive patterns
Strategy: try-catch
Validate before calling
const res = await fetch(`${registry}/${encodeURIComponent(name)}`);
const info = await res.json();
if (info.versions?.[version]) throw new Error(`Version ${version} already published; bump version`); Try / catch
try { await publish() } catch (e) { if (e.response?.status === 409 && /Package already exists/i.test(e.message ?? '')) { console.error('Bump version in package.json or delete the existing pack version'); } else throw e } Prevention
- Bump versions before every publish
- Make CI publish steps idempotent/skippable on retry
- Check for existing name+version before scripted deploys
When it happens
Trigger: Running 'npm publish' twice for the same package name+version in the same OneDev project; CI retrying a publish that already succeeded; manually re-deploying an already-uploaded artifact.
Common situations: CI pipelines without idempotency re-running publish steps after a later-stage failure; forgetting to bump the version in package.json; shared packages published by multiple branches with fixed versions.
Understand the failure class
Background: "already exists" / EEXIST / FileAlreadyExistsException: what the 'file already exists' error means and how to fix it — this error's family across 37 libraries.
Related errors
- Can not redeploy package: %s:%s
- Package metadata exceeds maximum size:
- File length incorrect:
- Integrity check failed:
- Package already exists (name: ${name}, version: ${version})
AI-assisted analysis of theonedev/onedev@d44925c47c (2026-09-06).
Data as JSON: /api/errors/5fa4cd2f28e7770e.
Report an issue: GitHub.