Skip to content

Conversation

@yashwantbezawada
Copy link

Summary

This PR clarifies the documentation for npm version to explicitly describe its behavior when the current version is a prerelease version.

Problem

The current documentation states that when using patch, minor, or major arguments, "the existing version will be incremented by 1 in the specified field." However, this is incomplete and misleading when the current version is a prerelease.

When the current version is a prerelease (e.g., 1.2.0-5), running npm version patch (or minor/major) will simply remove the prerelease suffix without incrementing the version number. The result would be 1.2.0, not 1.2.1.

This undocumented behavior has led to:

  • Developer confusion when the version doesn't increment as expected
  • Incorrect guidance from LLMs trained on the incomplete documentation

Solution

Added a note immediately after the existing sentence to clarify this behavior:

Note: If the current version is a prerelease version, patch, minor, and major will simply remove the prerelease suffix without incrementing the version number. For example, 1.2.0-5 becomes 1.2.0 with npm version patch, not 1.2.1.

Testing

The documentation change is straightforward and doesn't affect code behavior. The example provided matches the actual behavior of the semver.inc function from the node-semver package.

Fixes #8637

@yashwantbezawada yashwantbezawada requested a review from a team as a code owner November 16, 2025 00:28
When the current version is a prerelease (e.g., 1.2.0-5), running
npm version patch will remove the prerelease suffix without incrementing
the patch number (e.g., 1.2.0-5 becomes 1.2.0 with npm version patch,
not 1.2.1).

This behavior was not documented, leading to confusion for developers
and incorrect guidance from LLMs trained on the incomplete documentation.

Note: The behavior of minor and major with prerelease versions is more
complex and depends on the current version numbers, so this change
focuses specifically on patch behavior which is consistent.

Fixes: npm#8637
@yashwantbezawada yashwantbezawada force-pushed the docs/fix-version-prerelease-docs branch from a03a52c to d9dc9e6 Compare November 16, 2025 00:35
@yashwantbezawada
Copy link
Author

Update on Documentation Accuracy

After thorough testing with actual npm version commands, I've updated the documentation to be more precise:

Actual behavior verified:

  • 1.2.0-5 + npm version patch1.2.0 ✓ (removes prerelease, no increment)
  • 1.2.0-5 + npm version minor1.2.0 (also removes, but only because patch=0)
  • 1.2.0-5 + npm version major2.0.0 (increments because minor≠0)

The behavior of minor and major with prerelease versions is more complex and depends on the current version numbers. Therefore, the documentation now specifically mentions only patch, which has consistent behavior across all prerelease versions.

This matches the original issue report which was specifically about patch behavior and referenced the semver source code documentation for the patch case.

@wraithgar
Copy link
Member

That note seems to break up the flow of the rest of that section, it may need to move to after that paragraph.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[DOCS] docs for npm version state, incorrectly, that a version will be incremented by 1

2 participants