Dogfalo/materialize · error · Error

noUiSlider: 'range' 'min' and 'max' cannot be equal.

Error message

noUiSlider: 'range' 'min' and 'max' cannot be equal.

What it means

Thrown by testRange when entry.min === entry.max. The slider needs a non-zero span to map values to positions; equal endpoints collapse every value to the same point and would divide by zero in the percentage math downstream.

Solutions

  1. Ensure max is strictly greater than min.
  2. If data may be degenerate, expand the span: max = Math.max(min + 1, max).
  3. Defer noUiSlider.create until bounds actually differ.

Example fix

// before
range: { min: v, max: v }
// after
range: { min: v, max: v + span }
Defensive patterns

Strategy: validation

Validate before calling

if (opts.range.min === opts.range.max) {
  throw new Error('range min and max must differ');
}

Try / catch

try { noUiSlider.create(el, opts); }
catch (e) { if (/cannot be equal/.test(e.message)) { opts.range.max = opts.range.min + 1; /* retry */ } else throw e; }

Prevention

When it happens

Trigger: range: { min: 50, max: 50 }, dynamic config where both bounds resolve to the same number, or both defaulting to 0 before real data loads.

Common situations: Degenerate datasets with a single distinct value used for both bounds, an off-by-one in bound computation, or initializing the slider before the data range is known.

Related errors


AI-assisted analysis of Dogfalo/materialize@824e78248b (2026-08-13). Data as JSON: /api/errors/5a5684b694dd8bf9. Report an issue: GitHub.

Appendix: source

Thrown at extras/noUiSlider/nouislider.js:488

        // for linear sliders. Overwritten if set in 'range'.
        parsed.singleStep = entry;
    }

    function testRange ( parsed, entry ) {

        // Filter incorrect input.
        if ( typeof entry !== 'object' || Array.isArray(entry) ) {
            throw new Error("noUiSlider: 'range' is not an object.");
        }

        // Catch missing start or end.
        if ( entry.min === undefined || entry.max === undefined ) {
            throw new Error("noUiSlider: Missing 'min' or 'max' in 'range'.");
        }

        // Catch equal start or end.
        if ( entry.min === entry.max ) {
            throw new Error("noUiSlider: 'range' 'min' and 'max' cannot be equal.");
        }

        parsed.spectrum = new Spectrum(entry, parsed.snap, parsed.dir, parsed.singleStep);
    }

    function testStart ( parsed, entry ) {

        entry = asArray(entry);

        // Validate input. Values aren't tested, as the public .val method
        // will always provide a valid location.
        if ( !Array.isArray( entry ) || !entry.length ) {
            throw new Error("noUiSlider: 'start' option is incorrect.");
        }

        // Store the number of handles.
        parsed.handles = entry.length;

View on GitHub (pinned to 824e78248b)