Skip to content

[BUG] * || 1.2.3-alpha won't match 1.2.3-alpha (when includePrerelease = false) #906

Open

Description

@duckki

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

With semver@7.8.5 and the default options:

const semver = require('semver')

semver.satisfies('1.2.3-alpha', '1.2.3-alpha')      // true
semver.satisfies('1.2.3-alpha', '*')                // false
semver.satisfies('1.2.3-alpha', '* || 1.2.3-alpha') // false
semver.satisfies('1.2.3-alpha', '1.2.3-alpha || *') // false

new semver.Range('* || 1.2.3-alpha').range // ''

The explicit prerelease alternative matches on its own, but adding * || makes it stop matching. The same result occurs with the alternatives reversed. This is reproducible from the unmodified v7.8.5 tag (Node v22.23.3).

The range constructor collapses the whole OR range to * when any alternative is a wildcard, before prerelease eligibility is checked. This discards the explicit prerelease alternative and changes the set of matching versions.

Expected Behavior

The README's range description says a range matches when at least one ||-separated comparator set matches, and its prerelease rule checks for an eligible comparator within a comparator set. Thus 1.2.3-alpha should match the explicit 1.2.3-alpha alternative even though the wildcard alternative does not admit prereleases. In #183, @isaacs explicitly noted that * || 1.0.0-prerelease is different from * for this reason.

The Range.constructor shouldn't collapse * || 1.2.3-alpha into just *, when includePrerelease is false and one of the other comparators has a prerelease version.

Steps To Reproduce

n/a

Environment

n/a

Activity

  1. isaacs commented on Sep 27, 2026

    @isaacs
    Contributor

    This is indeed a bug. Prerelease ranges cannot be collapsed into * if includePrereleases is false.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bugthing that needs fixingNeeds Triageneeds an initial review

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions