Renaming a published NPM module

Npm

Npm Problem Overview


Is there any way to rename an NPM module that has already been published? I want to change the name of my module to more accurately match the API it exposes but would not like to leave people who have already installed it in the lurch.

Npm Solutions


Solution 1 - Npm

There isn't any exposed way to do that. When I've encountered this in the past the approach I took was:

> npm deprecate %ProjectName%@"<=put-latest-version-here" "WARNING: This project has been renamed to %NewProjectName%. Install using %NewProjectName% instead."

npm Deprecate instructions

Solution 2 - Npm

In simple words no you can't. But npm provides you a different solution called npm deprecate.

What it does is it marks a particular version or version ranges of that package as deprecated. So next if someone tries to install this package they get a warning package deprecated along with your custom message, in which you can easily specify your new package name.

Usage:

npm deprecate my-package-name@"< latest-version" "your message"

Your message can be any thing like:

WARNING: This project has been renamed to your-new-package-name. Install using new-package-name instead.

Solution 3 - Npm

In less than 24 hours i ran following command to delete wrong package.

npm unpublish <wrong package name> --force

Solution 4 - Npm

Someone has built a handy little npm plugin for doing this easily 

https://www.npmjs.com/package/@tiaanduplessis/pkg-rename

  1. Install the package using npm -g install @tiaanduplessis/pkg-rename
  2. Rename your npm module in the package.json file and save it
  3. run pkg-rename old-package-name

From the documentation:

>This will get the latest version of the old package from npm and deprecate this and all previous published versions with a message: > > >WARNING: This project has been renamed to new-package-name. Install using new-package-name instead. >

You can also add the --publish flag to publish the new package name as part of the same action.

pkg-rename old-package-name --publish

Remember, rename the package in package.json first, then run the pkg-rename command.

Solution 5 - Npm

From the documentation:

> Registry data is immutable, meaning once published, a package cannot > change. We do this for reasons of security and stability of the users > who depend on those packages.

However newly published packages - within 72 hours - can be unpublished by running:

npm unpublish <package_name> -f

This will remove the package from the NPM registry if it was published less than 72 hours ago. Then you can change your package's name and publish it again.

> Caution: You need to wait 24 hours if you try to republish package > with the same name

Solution 6 - Npm

I once was in this situation. I published a package with the name bowser-or-node instead of browser-or-node.

There's no way to rename a package, you have to deprecate and publish a new package.

Although there's one other option. If you just published your package (less than 24 hours from time of publish) and if you're sure you're okay with deleting the package and publish a new one with the right name, you can go ahead and do it. But NPM won't allow you to delete the package once it's been 24 hours since the time of publish.

Fortunately I figured out that I published with the wrong name in less than 20 minutes. So I just deleted and published again with a new name.

Solution 7 - Npm

Something marvelous just happened to me: I managed to rename a package. It was originally known as stdout-renderer, but I changed every possible occurence of the name, and republished it after having deprecated the original and voila it shows up under its new name (cli-artist) undeprecated in the newly updated list. I'm not sure which field to change, but I would imagine it be in package.json because that's the only one where the casing matched in my case.

hope that helps!

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionthekevinscottView Question on Stackoverflow
Solution 1 - NpmPeter FlanneryView Answer on Stackoverflow
Solution 2 - NpmUjjwalView Answer on Stackoverflow
Solution 3 - NpmSheikh Abdul WahidView Answer on Stackoverflow
Solution 4 - NpmDaniel TononView Answer on Stackoverflow
Solution 5 - NpmNedko DimitrovView Answer on Stackoverflow
Solution 6 - NpmDinesh PandiyanView Answer on Stackoverflow
Solution 7 - NpmJ-CakeView Answer on Stackoverflow