34

I've updated my package using npm version minor to go from 0.4.0 to 0.5.0, and both package.json and package-lock.json reflect this. However when I run the npm publish command it says:

You cannot publish over the previously published versions: 0.4.0

Is there another place I need to update the semver in order to publish?

user1795832
  • 2,080
  • 8
  • 29
  • 50

8 Answers8

33

This helped me:

Open Command Prompt and do the following steps.

  1. npm version <new_Version_No>
  2. npm publish
Adrita Sharma
  • 21,581
  • 10
  • 69
  • 79
  • Is there a way to enhance my `package.json` in such a way that it always installs the latest version available on npm for a particular dependency ? something like `"black-duck-lib": "_latest_",`. I dont want to open a separate question for this small thing. plz help. – Tanzeel Oct 26 '21 at 18:24
13

In your package.json, there might exist a publish script command with content of npm publish ..., remove or rename the publish command in your scripts of package.json if there is one.

Take the following code for example, this scripts.publish command will again be triggered by npm publish --access public, running recursively.

"scripts": {
 "publish": "npm publish --access public" // this was being triggered by running `npm publish`
},
Iceberg
  • 2,744
  • 19
  • 19
12

take a look at your package.json. Is the version actually set to 0.5.0? If not consider setting it manually there. NPM is telling you that you already have a version 0.4.0 and it cannot publish it again. So it seems to think that it's still on 0.4.0.

MarvinJWendt
  • 2,357
  • 1
  • 10
  • 36
5

npm version [patch|minor|major|<version_no>] should be done to bump up the version and then

npm publish for public visibility add --access public

This should do it.

Mukul Anand
  • 606
  • 6
  • 24
3

It happens when there is already npm module with same version.

We need to increment the npm module version and publish it again.

Yuvraj Patil
  • 7,944
  • 5
  • 56
  • 56
2

For some reason I was getting this error when I was trying to increase my version from 0.0.0 to 0.0.1. However, updating from 0.0.0 to 0.1.0 worked just fine.

yegor256
  • 102,010
  • 123
  • 446
  • 597
1

You can try the following:

  1. Update npm version to latest.
  2. cd into the parent folder (of the folder containing package.json i.e. cd into A if your files are A/B/package.json) and then run the command npm publish B.

Doing both fixed the issue for me.

Gaurang Tandon
  • 6,504
  • 11
  • 47
  • 84
0

As other mentioned just You already publish this version! so increment that version for example if it (1.1.1) change it to(1.1.2) then npm i

Gaş Bîn
  • 69
  • 1
  • 6