Skip to content

Instantly share code, notes, and snippets.

@SHSharkar
Created November 16, 2023 18:59
Show Gist options
  • Save SHSharkar/76c44458b454d470d300ea6695e8688f to your computer and use it in GitHub Desktop.
Save SHSharkar/76c44458b454d470d300ea6695e8688f to your computer and use it in GitHub Desktop.
Deprecating NPM Package Versions

Deprecating NPM Package Versions

This document provides a step-by-step guide on how to deprecate specific versions of an npm package. The process involves using the npm deprecate command.

Prerequisites

  • Ensure you have npm installed and are logged in to an account with permission to publish and manage the package.
  • You should have Node.js and npm installed on your system.

Deprecation Process

1. Login to NPM

Before deprecating any versions, you must be logged into npm with the correct account.

npm login

Enter your credentials as prompted.

2. Deprecate Specific Versions

To deprecate specific versions of your package, use the npm deprecate command. The syntax is as follows:

npm deprecate <package-name>@'<version-range>' '<deprecation-message>'
  • <package-name>: Your package name.
  • <version-range>: The range of versions you want to deprecate.
  • <deprecation-message>: The message that will be shown when someone tries to use a deprecated version.

Example:

To deprecate versions from 4.0.0 (exclusive) to 5.2.0 (exclusive) for a package named gitwz:

npm deprecate gitwz@">4.0.0 <5.2.0" "This version is deprecated. Please upgrade to 5.2.0."

3. Verify Deprecation

After running the deprecation command, you can verify the deprecation by:

  • Checking the package page on npmjs.com.
  • Trying to install one of the deprecated versions. npm will display the deprecation warning.

4. Update Documentation

Update your README.md or other relevant documentation to inform users about the deprecation and guide them towards upgrading to the latest version.

Best Practices

  • Follow semantic versioning (semver) practices when releasing new versions.
  • Clearly communicate deprecations to users through documentation and release notes.

Note

Deprecating a version does not remove it from the npm registry; it simply flags the version as outdated and advises against its use.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment