npm / cli

the package manager for JavaScript
https://docs.npmjs.com/cli/
Other
8.33k stars 3.06k forks source link

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

Open AllanOricil opened 1 month ago

AllanOricil commented 1 month ago

Is there an existing issue for this?

This issue exists in the latest npm version

Current Behavior

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

npm unpublish @namespace/package-name@vx.x.x -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/package-name@vx.x.x -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 commented 1 month ago

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...

milaninfy commented 1 month ago

@AllanOricil I tested and it's working as expected. I believe could you please check the syntax npm unpublish @namespace/package-name@x.x.x not include v in the version specification so e.g. npm unpublish @namespace/package-name@1.2.3

~/workarea/rep/testpkg $ npm view @myscope/testpkg versions
[ '1.2.0', '1.3.0' ]
~/workarea/rep/testpkg $ npm unpublish @myscope/testpkg@1.2.0
- @myscope/testpkg@1.2.0
~/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
AllanOricil commented 1 month ago

@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
milaninfy commented 4 weeks ago

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.

AllanOricil commented 4 weeks ago

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

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

shadowspawn commented 4 weeks ago

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.