How to Update an npm Package (Fixing "You cannot publish over the previously published versions")


Suppose we’ve published a npm package successfully, and we can view our package at:

https://npmjs.com/package/<package_name>

Now, let’s say we’ve made an update, but npm publish seems to return “You cannot publish over the previously published versions”.

How can we properly update the package?

Semantic Versioning

By updating the contents of our package, we’ll be updating the version of our package. Before specifying the version number, be sure to read up on semantic versioning.

In summary, suppose we’re on version 1.0.0 (major.minor.patch):

If the update is a patch release (small changes), we’ll want to increment the last part of version number.

npm version patch

If the update is a minor release (new features), we’ll want to increment the middle part of version number.

npm version minor

If it is a major release (major features or major issue fixes), we’ll want to increment the first part of version number.

npm version major

Instructions to Update

First, I’ll assume we’re in the local root directory of the package we want to update.

Let’s log into npm.

npm login

Let’s make our version change. We can specify a specific version or use the patch, minor, major updates.

npm version 1.0.2
npm version patch

Then, we can successfully publish.

npm publish

Finally, we can check if everything was published correctly.

https://npmjs.com/package/<package_name>