You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG] npm unpublish --force <package-name>@<version> deletes all versions #7015
To unpublish a single package version, run npm unpublish <package_name>@<version>.
If all the versions of a package can be unpublished, you can unpublish all versions at once by running npm unpublish <package_name> --force.
It does not state that --force ignores any specified version, which is mind blowing. 🤯
I AM ANGRY!!!!!!!!!!!!!!
😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡
If npm is asking you to type --force whent it detects that you are unpublishing the only version of a package. Was that the only version of the package that existed when you typed this command?
The output telling you to use --force says:
Refusing to delete entire project.
Run with --force to do this.
npm is telling you it's trying to delete the whole project here.
There are a lot of safeguards in npm that should prevent this from happening. It will only send a total package unpublish if you specify just a package name or are unpublishing the last existing version of a package.
Can you double check your shell history to see exactly what you typed?
We can't reproduce this on our end w/ any combination of parameters.
Was that the only version of the package that existed when you typed this command?
No, there were multiple versions of the package published, f.e. 0.8.0, 0.9.0, and 0.10.0, among others.
The output telling you to use --force says:
Refusing to delete entire project.
Run with --force to do this.
npm is telling you it's trying to delete the whole project here.
Indeed that was fishy. I was trying to delete a specific version, and it was giving that message.
It will only send a total package unpublish if you specify just a package name or are unpublishing the last existing version of a package.
Can you double check your shell history to see exactly what you typed?
The commands in the OP were what I ran, but with single quotes around the package@version, while the last three published versions at the time were 0.10.0, 0.10.1, and 0.10.2.
There you can see my commands. The first one gave me the --force message. I tried it with a dry run next, and with single quotes just in case. Then I tried again without --force but with single quotes and it told me I needed to use --force. Then the second-to-last command deleted all versions. I tried the last command before I realized all versions were deleted.
There's several versions of the package now, and I was able to install version 0.11.0. Some more questions to aid our investigation:
I of course went and published a new patch version for each minor to restore the delete package because support told me it could not be restored. I published a new patch for each 0.X version that got deleted. For example you can see version 0.9.4 which is a re-publish of 0.9.3 that got deleted, or for example 0.7.6 is a re-publish of 0.7.5 that was deleted. 0.10.3 is a re-publish of 0.10.0 (I was trying to delete 0.10.1 and 0.10.2, and I re-published 0.10.2 as 0.11.0).
What evidence did you see that the entire package was deleted?
It became a 404 page on npmjs.com, until I re-published the new patches for each minor.
Did you execute npm unpublish --force @lume/cli@0.10.1 with or without single quotes around @lume/cli@0.10.1? What shell did you use?
Sorry, the OP was not entirely accurate: I used single quotes on the command that did the deletion of all versions (as per above history output)
I'm not angry anymore (and was never angry at anyone specifically), as I re-published the patches and went on my way. At worst, someone at a previous company might get an error and need to update a package.json version or a lock file.
Hope you're able to eventually reproduce this, because it really did happen!
❯ npm unpublish --dry-run '@lume/element@0.11.1'
npm WARN ignoring workspace config at /Users/trusktr/src/lume+lume/packages/element/.npmrc
npm ERR! code EUSAGE
npm ERR!
npm ERR! Refusing to delete entire project(s).
npm ERR! Run with --force to do this.
npm ERR!
npm ERR! Remove a package from the registry
npm ERR!
npm ERR! Usage:
npm ERR! npm unpublish [<package-spec>]
npm ERR!
npm ERR! Options:
npm ERR! [--dry-run] [-f|--force]
npm ERR! [-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
npm ERR! [-ws|--workspaces]
npm ERR!
npm ERR! Run "npm help unpublish"for more info
npm ERR! A complete log of this run can be found in: /Users/trusktr/.npm/_logs/2023-11-29T05_27_53_659Z-debug-0.log
where the latest published version is 0.11.4, and I have:
Node: v20.6.1
npm: 10.2.0
Here's a full reproduction on my end:
git clone git@github.com:lume/lume.git lume-npm-unpublish-test
cd lume-npm-unpublish-test
git checkout v0.3.0-alpha.34
git submodule update --init
cd packages/element/
npm unpublish --dry-run '@lume/element@0.11.1'
Sometimes I can reproduce, sometimes I can't. Does it have to do with git submodules? For example I canceled (ctrl+c) out of the git submodule update --init half way through, then ran it again to make it complete, and when I went into packages/element/ I could no longer reproduce and would not get the --force error. Then I tried the reproduction steps over again and did not cancel git submodule update --init and now I get the error every time.
Not sure about the ctrl+c state but if I had to guess it would be a state where the workspace's package.json hadn't gotten written to disk.
This is definitely an issue w/ unpublishing workspaces and I'm surprised it went this long w/o any one seeing it. Your reproduction example was key to solving it, cheers.
The TLDR here is that the unpublish workspaces code was written before "automatically detect workspaces" was implemented. So when you're in that directory the code that is running was intended to be ran as npm unpublish -w foo which was conceptually equivalent to "cd foo; npm unpublish"
Activity
wraithgar commentedon Nov 22, 2023
If npm is asking you to type
--forcewhent it detects that you are unpublishing the only version of a package. Was that the only version of the package that existed when you typed this command?The output telling you to use
--forcesays:npm is telling you it's trying to delete the whole project here.
wraithgar commentedon Nov 22, 2023
There are a lot of safeguards in npm that should prevent this from happening. It will only send a total package unpublish if you specify just a package name or are unpublishing the last existing version of a package.
Can you double check your shell history to see exactly what you typed?
We can't reproduce this on our end w/ any combination of parameters.
hashtagchris commentedon Nov 22, 2023
There's several versions of the package now, and I was able to install version
0.11.0. Some more questions to aid our investigation:npm unpublish --force @lume/cli@0.10.1with or without single quotes around@lume/cli@0.10.1? What shell did you use?ljharb commentedon Nov 23, 2023
Unpublished package versions can't ever be restored or republished, generally, so the second bullet point shouldn't be possible.
trusktr commentedon Nov 29, 2023
No, there were multiple versions of the package published, f.e. 0.8.0, 0.9.0, and 0.10.0, among others.
Indeed that was fishy. I was trying to delete a specific version, and it was giving that message.
The commands in the OP were what I ran, but with single quotes around the package@version, while the last three published versions at the time were 0.10.0, 0.10.1, and 0.10.2.
There you can see my commands. The first one gave me the
--forcemessage. I tried it with a dry run next, and with single quotes just in case. Then I tried again without --force but with single quotes and it told me I needed to use --force. Then the second-to-last command deleted all versions. I tried the last command before I realized all versions were deleted.I of course went and published a new patch version for each minor to restore the delete package because support told me it could not be restored. I published a new patch for each
0.Xversion that got deleted. For example you can see version 0.9.4 which is a re-publish of 0.9.3 that got deleted, or for example 0.7.6 is a re-publish of 0.7.5 that was deleted. 0.10.3 is a re-publish of 0.10.0 (I was trying to delete 0.10.1 and 0.10.2, and I re-published 0.10.2 as 0.11.0).It became a 404 page on npmjs.com, until I re-published the new patches for each minor.
Sorry, the OP was not entirely accurate: I used single quotes on the command that did the deletion of all versions (as per above
historyoutput)trusktr commentedon Nov 29, 2023
I'm not angry anymore (and was never angry at anyone specifically), as I re-published the patches and went on my way. At worst, someone at a previous company might get an error and need to update a package.json version or a lock file.
Hope you're able to eventually reproduce this, because it really did happen!
trusktr commentedon Nov 29, 2023
I'm able to consistently reproduce the following:
where the latest published version is 0.11.4, and I have:
Node: v20.6.1
npm: 10.2.0
Here's a full reproduction on my end:
Maybe workspaces throws something off?
trusktr commentedon Nov 29, 2023
Sometimes I can reproduce, sometimes I can't. Does it have to do with git submodules? For example I canceled (ctrl+c) out of the
git submodule update --inithalf way through, then ran it again to make it complete, and when I went intopackages/element/I could no longer reproduce and would not get the --force error. Then I tried the reproduction steps over again and did not cancelgit submodule update --initand now I get the error every time.wraithgar commentedon Nov 29, 2023
Not sure about the ctrl+c state but if I had to guess it would be a state where the workspace's package.json hadn't gotten written to disk.
This is definitely an issue w/ unpublishing workspaces and I'm surprised it went this long w/o any one seeing it. Your reproduction example was key to solving it, cheers.
wraithgar commentedon Nov 29, 2023
The TLDR here is that the unpublish workspaces code was written before "automatically detect workspaces" was implemented. So when you're in that directory the code that is running was intended to be ran as
npm unpublish -w foowhich was conceptually equivalent to "cd foo; npm unpublish"trusktr commentedon Dec 1, 2023
Yay! 🙏 Happy holidays.
ci: drop --force from unpublish, document npm's dependents policy