Dogfalo/materialize · error · Error

noUiSlider: 'snap' option must be a boolean.

Error message

noUiSlider: 'snap' option must be a boolean.

What it means

Thrown by testSnap when 'snap' is not typeof === 'boolean'. snap forces handles onto the nearest step; the library refuses truthy/falsy coercions like 1/0 or the strings 'true'/'false'. Note the value is assigned to parsed.snap before the type check, but the throw still aborts initialization.

Source

Thrown at extras/noUiSlider/nouislider.js:518

        if ( !Array.isArray( entry ) || !entry.length ) {
            throw new Error("noUiSlider: 'start' option is incorrect.");
        }

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

        // When the slider is initialized, the .val method will
        // be called with the start options.
        parsed.start = entry;
    }

    function testSnap ( parsed, entry ) {

        // Enforce 100% stepping within subranges.
        parsed.snap = entry;

        if ( typeof entry !== 'boolean' ){
            throw new Error("noUiSlider: 'snap' option must be a boolean.");
        }
    }

    function testAnimate ( parsed, entry ) {

        // Enforce 100% stepping within subranges.
        parsed.animate = entry;

        if ( typeof entry !== 'boolean' ){
            throw new Error("noUiSlider: 'animate' option must be a boolean.");
        }
    }

    function testAnimationDuration ( parsed, entry ) {

        parsed.animationDuration = entry;

        if ( typeof entry !== 'number' ){

View on GitHub (pinned to 824e78248b)

Solutions

  1. Use the literal true or false.
  2. Coerce explicitly: snap: raw === true || raw === 'true'.
  3. Omit snap to keep the default (false).

Example fix

// before
snap: el.dataset.snap
// after
snap: el.dataset.snap === 'true'
Defensive patterns

Strategy: type-guard

Validate before calling

if (opts.snap != null && typeof opts.snap !== 'boolean') {
  throw new TypeError('snap must be a boolean');
}

Type guard

function isBoolean(v) { return typeof v === 'boolean'; }

Try / catch

try { noUiSlider.create(el, opts); }
catch (e) { if (/snap' option must be a boolean/.test(e.message)) { opts.snap = Boolean(opts.snap); /* retry */ } else throw e; }

Prevention

When it happens

Trigger: snap: 1, snap: 0, snap: 'true', or snap: 'false' (both strings are truthy and would also behave wrong if accepted).

Common situations: Reading snap from a checkbox's value attribute or dataset (always a string), from JSON like {"snap": 1}, or toggling it with a numeric flag.

Related errors


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