Seregwethrin
Seregwethrin

Reputation: 1399

Publishing an NPM pkg to Github Packages fails with EPUBLISHCONFLICT and version @undefined but it still ends up there with the right version

I am publishing an NPM package to a private Github Packages in a private repo.

I am getting Error: Cannot publish @user/libs@undefined over existing version.
The right version is in the package.json which does not exist in the upstream.

But the package ends up published up there fine with the right version when I go to the repo! I can install and use the package with its version fine.

I tried to update the version with npm version patch as well as manually. I've tried having a matching git tag with e.g. v1.2.2. I've put the correct version in package-lock.json as well as package.json.

I've deleted all the packages from the Github repo, let it have no packages and it is still the same.

Tried npm cache clean --force

I am on Node 18 but initially I tried with Node 20 with its latest NPM npm and result is the exact same.

Here is the important bit from the verbose log.

42 notice === Tarball Details ===
43 notice name:          @user/libs
43 notice version:       1.2.2
43 notice filename:      user-libs-1.2.2.tgz
43 notice package size:  93.1 kB
43 notice unpacked size: 649.3 kB
43 notice shasum:        34f4360863d82d5d3101ab8248d8f73610c77f32
43 notice integrity:     sha512-jamF7x3PnHNR5[...]Z0LOJVSQkIiuA==
43 notice total files:   388
44 notice
45 notice Publishing to https://npm.pkg.github.com with tag latest and default access
46 http fetch PUT 409 https://npm.pkg.github.com/@user%2flibs 559ms
47 http fetch GET 200 https://npm.pkg.github.com/@user%2flibs?write=true 240ms (cache updated)
48 timing command:publish Completed in 1095ms
49 verbose stack Error: Cannot publish @user/libs@undefined over existing version.
49 verbose stack     at patchMetadata (/Users/user/.nvm/versions/node/v18.17.1/lib/node_modules/npm/node_modules/libnpmpublish/lib/publish.js:210:7)
49 verbose stack     at publish (/Users/user/.nvm/versions/node/v18.17.1/lib/node_modules/npm/node_modules/libnpmpublish/lib/publish.js:76:25)
49 verbose stack     at async otplease (/Users/user/.nvm/versions/node/v18.17.1/lib/node_modules/npm/lib/utils/otplease.js:4:12)
49 verbose stack     at async Publish.exec (/Users/user/.nvm/versions/node/v18.17.1/lib/node_modules/npm/lib/commands/publish.js:123:7)
49 verbose stack     at async module.exports (/Users/user/.nvm/versions/node/v18.17.1/lib/node_modules/npm/lib/cli-entry.js:61:5)
50 verbose pkgid @user/libs
51 verbose cwd /Users/user/projects/libs
52 verbose Darwin 22.6.0
53 verbose node v18.17.1
54 verbose npm  v9.8.1
55 error code EPUBLISHCONFLICT
56 error publish fail Cannot publish over existing version.
57 error publish fail Update the 'version' field in package.json and try again.
58 error publish fail
59 error publish fail To automatically increment version numbers, see:
60 error publish fail     npm help version
61 verbose exit 1

Upvotes: 2

Views: 1193

Answers (1)

Seregwethrin
Seregwethrin

Reputation: 1399

This is caused because I had "scripts": { "publish": "npm publish" } in package.json and running npm publish or npm run publish was causing it to be run twice... Just naming it to publish2 made it succeed.

Upvotes: 4

Related Questions