Skip to main content

How to Publish a Test Version of Your NPM Package

When developing an NPM package, you often need to test pre-release versions before publishing a stable release. Whether for internal development, beta testing, or experimental features, following the right approach ensures a smooth and structured deployment process.

This guide walks you through publishing a test version of your package on NPM without affecting production releases.


✅ Steps to Publish a Test Version on NPM

1️⃣ Log In to NPM

Before publishing, ensure you are authenticated with NPM:

npm login

This command will prompt for your NPM username, password, and email. Once authenticated, you can proceed with publishing your test package.


2️⃣ Update package.json

Modify your package.json file to include a test version identifier:

{
"name": "@your-org/your-package",
"version": "1.0.0-beta.0", // Add 'beta', 'alpha', or a unique tag
"publishConfig": {
"access": "public"
}
}

Versioning Guide

  • 1.0.0-alpha.1 → Early experimental release
  • 1.0.0-beta.1 → Feature complete, but in testing
  • 1.0.0-rc.1 → Release Candidate (near-final version)

The publishConfig.access setting ensures your package is publicly available (remove it for private packages).


3️⃣ Use --tag to Publish a Test Version

To publish the test version, run:

npm publish --tag beta

How This Works:

  • By default, running npm install @your-org/your-package installs only the latest stable version.
  • Using --tag beta ensures that your test version does not overwrite your production release.
  • Developers can install the test version explicitly:
npm install @your-org/your-package@beta

This allows the team to test the beta release without affecting users installing the latest stable version.


4️⃣ Automate Versioning with npm version

Instead of manually updating package.json, you can automate versioning:

npm version prerelease --preid=beta

This command will automatically increment the beta version to the next pre-release (e.g., 1.0.1-beta.1).

Then, publish it with:

npm publish --tag beta

Automating versioning ensures consistent releases and prevents accidental version duplication.


5️⃣ Install the Test Version

Once the test version is published, developers can install it like this:

npm install @your-org/your-package@beta

For specific versions, use:

npm install @your-org/your-package@1.0.0-beta.1

This ensures that the correct version is being tested before rolling out the final release.


๐Ÿš€ Summary of Commands

Step Command Login to NPM npm login Set a test version in package.json "version": "1.0.0-beta.0" Publish as beta npm publish --tag beta Auto-update version npm version prerelease --preid=beta Install test version npm install @your-org/your-package@beta


๐Ÿ›  Additional Tips for Testing

1️⃣ Use a Private NPM Registry

If you don’t want to publish your test versions publicly, consider using Verdaccio (a lightweight private NPM registry):

npm set registry http://localhost:4873/

This allows internal teams to test packages before publishing to the public NPM registry.

2️⃣ Publish to GitHub Packages (For Private Testing)

If your team is using GitHub Packages, update package.json like this:

"publishConfig": {
"registry": "https://npm.pkg.github.com/"
}

Then publish using:

npm publish

3️⃣ Automate Publishing in CI/CD

Using GitHub Actions or Jenkins, you can automate NPM publishing by adding a workflow like this:

- name: Publish Test Version
run: |
npm version prerelease --preid=beta
npm publish --tag beta

This ensures that new test versions are automatically published for internal teams to validate before release.


๐ŸŽฏ Final Thoughts

Publishing test versions of your NPM package allows your team to test, iterate, and validate updates before pushing them to production. By using scoped versions (beta, alpha, rc), you prevent breaking changes from affecting live users while ensuring a smooth development cycle.

Following these best practices will help your team maintain a robust, error-free, and well-managed package release process. ๐Ÿš€


Have questions about publishing NPM packages? Let me know in the comments!


Popular posts from this blog

Xcode and iOS Version Mismatch: Troubleshooting "Incompatible Build Number" Errors

Have you ever encountered a frustrating error while trying to run your iOS app in Xcode, leaving you scratching your head? A common issue arises when your device's iOS version is too new for the Xcode version you're using. This often manifests as an "incompatible build number" error, and looks like this: DVTDeviceOperation: Encountered a build number "" that is incompatible with DVTBuildVersion. This usually happens when you are testing with beta versions of either iOS or Xcode, and can prevent Xcode from properly compiling your storyboards. Let's explore why this occurs and what you can do to resolve it. Why This Error Occurs The core problem lies in the mismatch between the iOS version on your test device and the Software Development Kit (SDK) supported by your Xcode installation. Xcode uses the SDK to understand how to build and run apps for specific iOS versions. When your device runs a newer iOS version than Xcode anticipates, Xcode mi...

How to Fix the “Invariant Violation: TurboModuleRegistry.getEnforcing(…): ‘RNCWebView’ Could Not Be Found” Error in React Native

When working with React Native, especially when integrating additional libraries like react-native-signature-canvas , encountering errors can be frustrating. One such error is: Invariant Violation: TurboModuleRegistry. getEnforcing (...): 'RNCWebView' could not be found This error often occurs when the necessary dependencies for a module are not properly linked or when the environment you’re using doesn’t support the required native modules. Here’s a breakdown of how I encountered and resolved this issue. The Problem I was working on a React Native project where I needed to add the react-native-signature-canvas library to capture user signatures. The installation process seemed straightforward: Installed the package: npm install react-native-signature- canvas 2. Since react-native-signature-canvas depends on react-native-webview , I also installed the WebView package: npm install react- native -webview 3. I navigated to the iOS directory and ran: cd ios pod install Everythi...

Fixing FirebaseMessagingError: Requested entity was not found.

If you’re working with Firebase Cloud Messaging (FCM) and encounter the error: FirebaseMessagingError: Requested entity was not found. with the error code: messaging/registration-token-not-registered this means that the FCM registration token is invalid, expired, or unregistered . This issue can prevent push notifications from being delivered to users. ๐Ÿ” Possible Causes & Solutions 1️⃣ Invalid or Expired FCM Token FCM tokens are not permanent and may expire over time. If you’re storing tokens in your database, some might be outdated. ✅ Solution: Remove invalid tokens from your database when sending push notifications. Refresh and store the latest FCM token when the app starts. Example: Automatically Refresh Token firebase. messaging (). onTokenRefresh ( ( newToken ) => { // Send newToken to your backend and update the stored token }); 2️⃣ Token Unregistered on Client Device A token might become unregistered if: The app is uninstalled on the user’s device. ...