'Google Artifact Registry: Unable to publish package with the same version even after package deletion

I'm trying to publish npm package to the google artifact registry (GAR).

A package with the same version has already been published, but I've deleted it manually from the GAR.

npm view <package-name>@0.1.3

<empty response>

But still unable to publish the package.

npm publish

npm ERR! code E400
npm ERR! 400 Bad Request - PUT https://<package-url> - Requested version(0.1.3) already exists.

Looks like it has been cached somewhere. If so is there any possibility to clear the cache?



Solution 1:[1]

Actually Cloud Artifacts Registry does not allow that, according to this documentation:

You can only publish a specific version of a package once. This is an npm restriction to ensure that the contents of a published package version are always the same. As a result, you cannot:

  • Overwrite a package version by publishing it again to the repository
  • Remove a package or its version from the repository, and then publish a package with the same name and version number

So you are going to have to create another version in order to publish the package.

Solution 2:[2]

Warning: this is NOT a solution for existing repositories that contain quite some packages and their versions!

There's still a way to do this, BUT it requires deleting and recreating the whole repository. So:

  1. Delete the whole repository
  2. Recreate the repository with the same name and options.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ralemos
Solution 2 Romko