41

Now that npm publish -f is deprecated, is there a workaround or a package that makes it possible to overwrite a target version after it's been published?

I know about semver; I still want npm publish -f.

Alexej Magura
  • 4,833
  • 3
  • 26
  • 40
  • I read about `npm unpublish`, but it doesn't seem to always work... since I can't seem to publish the same version after unpublishing it. – Alexej Magura Jan 10 '15 at 06:35
  • 5
    "[*Even if a package version is unpublished, that specific name and version combination can never be reused. In order to publish the package again, a new version number must be used.*](https://docs.npmjs.com/cli/unpublish)" So, I would say no, there probably isn't an alternative to replace a particular version once it's been published. – Jonathan Lonowski Jan 10 '15 at 06:41
  • There seems to be a direct correlation between the popularity of Bitcoin and Ethereum and the growing number of companies that ship their software with immutability in mind – Paul Razvan Berg Jan 29 '19 at 15:57
  • @PaulBerg So are you saying that Bitcoin/Ethereum are to blame for this fad? – Alexej Magura May 08 '19 at 17:41

5 Answers5

34

You can unpublish a specific version, and then republish it:

npm unpublish myModule@1.2.3

And then republish the version.

This works if the module is hosted on your own npm repo, but for registry.npmjs.org, you won't be able to reuse the version number after unpublishing, and there's a time-limit (72 hours) after which you can no longer unpublish. See the npm Unpublish Policy.

Noah Andrews
  • 353
  • 2
  • 14
davejlin
  • 903
  • 9
  • 18
  • 21
    warning if you do this for the only published version then you will need to wait 24hrs before publishing again – wasabi Jan 07 '20 at 15:54
26

someone said this on npm's github issue:

@nmrony You cannot overwrite previously-published packages anymore (since February 2014, if I recall correctly).

https://github.com/npm/npm/issues/8305#issuecomment-236412989

c0b0
  • 276
  • 4
  • 4
  • 6
    Is there no way to do this with snapshots? Like a maven style publish that lets you accumulate snapshots of the same version in the repo – gary69 Dec 17 '18 at 17:35
11

According to npm docs this unpublished versions cannot be republished,bump a patch version and publish

Once a package is unpublished, it cannot be republished. If you’ve unpublished a package by mistake, we’d recommend publishing again under a different name, or for unpublished versions, bumping the version number and publishing again.

So:

npm unpublish
npm version patch
npm publish

will do the job.

melloc
  • 833
  • 7
  • 13
  • I was looking for `npm version patch` because I wrote a module to publish modules for me. – Rehmat May 28 '21 at 07:48
  • `npm version patch` will not read actual version from remote. It will increment to what value is available on local. So, to get info from remote, do: `npm info MODULE-NAME`. – Rehmat May 28 '21 at 08:24
  • This makes sense from a security perspective. – a2f0 Jun 22 '22 at 03:51
9

This will probably not be viable but there's an overkill method

npm unpublish --force - will delete your entire project

wait 24 hours

npm publish

Pawel
  • 16,093
  • 5
  • 70
  • 73
0

I also faced similar issue.I published a new package with new version but same content.

npm publish --access public (version - 0.1.1)

Now, delete the original package.

npm unpublish -f package_name@0.1.0

wait 24 hours republish the original package & delete the new package.

npm publish --access public (version - 0.1.0)
npm unpublish -f package_name@0.1.1

Your package user will not find original version for 24 hours, so package manager will show drop down to choose other version & most will go with latest version.