cli icon indicating copy to clipboard operation
cli copied to clipboard

[BUG] npm unpublish outputs OK | 0 | 200 when package version doesn't exist

Open AllanOricil opened this issue 1 year ago • 6 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

This issue exists in the latest npm version

  • [X] I am using the latest npm

Current Behavior

I just published v0.2.1 and I can't unpublish it. (less than 72h)

npm unpublish @namespace/[email protected] -f does not throw exception, but does not work. I unpublished my package and it still present in npm. Because of that, I can't publish that version again

image

no error message, and this unpublish command doesn't work, even after npm login

image

Expected Behavior

at least an exception should appear if I can't unpublish a package

Steps To Reproduce

  1. publish a package with namespace (e.g. @namespace)
  2. wait it to appear on npm
  3. run npm unpublish @namespace/[email protected] -f
  4. verify no error appears on the terminal
  5. verify npm is still showing the package, even after days have passed
  6. verify that you can't publish the same version

Environment

//journeylab-tech-845044614340.d.codeartifact.us-east-2.amazonaws.com/npm/flowfuse/:_authToken = (protected) //journeylab-tech-845044614340.d.codeartifact.us-east-2.amazonaws.com/npm/node-ready/:_authToken = (protected) //registry.npmjs.org/:_authToken = (protected) registry = "https://registry.npmjs.org"

; "project" config from /Users/ec2-user/node-ready-ascend-data-storage/.npmrc

@node-ready:registry = "https://registry.npmjs.org/"

; node bin location = /Users/ec2-user/.nvm/versions/node/v18.19.1/bin/node ; node version = v18.19.1 ; npm local prefix = /Users/ec2-user/node-ready-ascend-data-storage ; npm version = 10.2.4 ; cwd = /Users/ec2-user/node-ready-ascend-data-storage ; HOME = /Users/ec2-user ; Run npm config ls -l to show all defaults.

AllanOricil avatar Jul 15 '24 15:07 AllanOricil

I can't understand how a simple feature like this keeps breaking. I updated npm to the 10.8.2 and tried to unpublish the whole package and just a version

image

and again it did not work...

AllanOricil avatar Jul 15 '24 15:07 AllanOricil

@AllanOricil I tested and it's working as expected. I believe could you please check the syntax npm unpublish @namespace/[email protected] not include v in the version specification so e.g. npm unpublish @namespace/[email protected]

~/workarea/rep/testpkg $ npm view @myscope/testpkg versions
[ '1.2.0', '1.3.0' ]
~/workarea/rep/testpkg $ npm unpublish @myscope/[email protected]
- @myscope/[email protected]
~/workarea/rep/testpkg $ npm view @myscope/testpkg versions
1.3.0
~/workarea/rep/testpkg $ npm unpublish @myscope/testpkg -f   
npm warn using --force Recommended protections disabled.
- @milansmeva/testpkg
~/workarea/rep/testpkg $ npm view @myscope/testpkg versions
npm error code E404
npm error 404 Unpublished on 2024-08-02T21:21:51.311Z
npm error 404
npm error 404  '@myscope/testpkg' is not in this registry.
npm error 404
npm error 404 Note that you can also install from a
npm error 404 tarball, folder, http url, or git url.
npm error A complete log of this run can be found in: /Users/milaninfy/.npm/_logs/2024-08-02T21_22_07_744Z-debug-0.log

milaninfy avatar Aug 02 '24 21:08 milaninfy

@milaninfy it is clearly not working as expected. If the version is wrong, or doesn't exist, it should tell "HEY IT IS WRONG!" and exit with 1 instead of 0.

image

AllanOricil avatar Aug 02 '24 23:08 AllanOricil

Behaviour is by design here, It exits correctly with code 0 if the version doesn't exist then it's effectively gone, however a logging would be useful here if the version doesn't exit.

milaninfy avatar Aug 09 '24 15:08 milaninfy

@milaninfy so NPM by design displays 200, OK and exit 0 when UMPUBLISH fails? weird.

  • How can a User know umpublish failed? even with --verbose, there is no way he can know it didn't work unless he/she opens NPM UI

  • How can a CI job know umpublish failed, and then display failure? can you give an example showing how to handle this type of error using major CI environments, like Github Actions? I have a Github Actions Workflow with an input for the package version. User can provide anything in that input. If User provides a version that doesn't exist, my CI Workflow will finish with Success. Does it make sense for you or @shadowspawn?

This is clearly a new known error type "UNKNOWN VERSION" which has to be treated as: 400, NOT OK, 1

AllanOricil avatar Aug 09 '24 19:08 AllanOricil

Hi @AllanOricil

I gave a thumbs-up to the comment which diagnosed the error in the command you were running. I had read your description (thanks for the clear description) but hadn't spotted the extra v. I wasn't offering an opinion on whether the behaviour was ideal.

I appreciate the lack of clues provided by the unpublish caused you some confusion and cost you some time.

Perhaps you could change the title of this issue to more accurately describe what turned out to be the problem.

shadowspawn avatar Aug 09 '24 21:08 shadowspawn

Duplicate of https://github.com/npm/cli/issues/2480

wyattscarpenter avatar Jul 10 '25 13:07 wyattscarpenter

I had the same issue and was able to fix it with https://github.com/npm/cli/issues/2480#issuecomment-3175787445

Tchekda avatar Aug 11 '25 16:08 Tchekda