[GH-ISSUE #866] Coerce does not preserve valid versions with prerelease identifiers #4803

Closed
opened 2026-06-13 13:12:10 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @alasdairhurst on GitHub (Aug 9, 2022).
Original GitHub issue: https://github.com/semver/semver/issues/866

Coerce specifically "Coerces a string to semver if possible". It does not work with ranges.
Given this description, any strings that i provide that happen to be valid semver versions, should be returned as-is.

Unfortunately, i've found that the prerelease identifier gets stripped off entirely.

semver.valid(semver.coerce('1.0.0-alpha.0'))
'1.0.0'
semver.valid(semver.coerce('1.0.0-alpha'))
'1.0.0'

I shouldn't have to provide loose (especially if i want to be strict), or includePrerelease but those options don't change the behavior either.

Originally created by @alasdairhurst on GitHub (Aug 9, 2022). Original GitHub issue: https://github.com/semver/semver/issues/866 Coerce specifically "Coerces a string to semver if possible". It does not work with ranges. Given this description, any strings that i provide that happen to be valid semver versions, should be returned as-is. Unfortunately, i've found that the prerelease identifier gets stripped off entirely. ``` semver.valid(semver.coerce('1.0.0-alpha.0')) '1.0.0' ``` ``` semver.valid(semver.coerce('1.0.0-alpha')) '1.0.0' ``` I shouldn't have to provide `loose` (especially if i want to be strict), or `includePrerelease` but those options don't change the behavior either.
Author
Owner

@alasdairhurst commented on GitHub (Aug 10, 2022):

Submitted to the wrong repo, apologies. This is what i was looking for. https://github.com/npm/node-semver/issues/357

<!-- gh-comment-id:1211040165 --> @alasdairhurst commented on GitHub (Aug 10, 2022): Submitted to the wrong repo, apologies. This is what i was looking for. https://github.com/npm/node-semver/issues/357
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/semver#4803