alvarotrigo/fullPage.js · error · TypeError

Array.from requires an array-like object - not null or undef

Error message

Array.from requires an array-like object - not null or undefined

What it means

Thrown by the Array.from polyfill (src/js/polyfills/array.from.js:37) at spec step 3, ReturnIfAbrupt after ToObject(arrayLike). When the first argument is null or undefined, ToObject fails and the polyfill throws this explicit TypeError. The native Array.from throws the same error; this code runs only where Array.from is missing.

Source

Thrown at src/js/polyfills/array.from.js:37

            return (number > 0 ? 1 : -1) * Math.floor(Math.abs(number));
        };
        var maxSafeInteger = Math.pow(2, 53) - 1;
        var toLength = function(value) {
            var len = toInteger(value);
            return Math.min(Math.max(len, 0), maxSafeInteger);
        };

        // The length property of the from method is 1.
        return function from(arrayLike /*, mapFn, thisArg */) {
            // 1. Let C be the this value.
            var C = this;

            // 2. Let items be ToObject(arrayLike).
            var items = Object(arrayLike);

            // 3. ReturnIfAbrupt(items).
            if (arrayLike == null) {
                throw new TypeError(
                    'Array.from requires an array-like object - not null or undefined'
                );
            }

            // 4. If mapfn is undefined, then let mapping be false.
            var mapFn = arguments.length > 1 ? arguments[1] : void undefined;
            var T;
            if (typeof mapFn !== 'undefined') {
                // 5. else
                // 5. a If IsCallable(mapfn) is false, throw a TypeError exception.
                if (!isCallable(mapFn)) {
                    throw new TypeError(
                        'Array.from: when provided, the second argument must be a function'
                    );
                }

                // 5. b. If thisArg was supplied, let T be thisArg; else let T be undefined.
                if (arguments.length > 2) {

View on GitHub (pinned to 49f15effa7)

Solutions

  1. Guard the input before conversion: if (value) { arr = Array.from(value); }.
  2. Default to an empty array-like when the source may be missing: Array.from(value || []).
  3. Fix the upstream lookup that returned null (e.g., the missing selector or unparseable JSON) rather than masking the symptom.
  4. If accepting user/config input, validate it is array-like (has a .length) before passing it in.

Example fix

// before
const nodes = Array.from(document.querySelector('.item'));
// querySelector returns null -> Array.from requires an array-like object

// after
const node = document.querySelector('.item');
const nodes = node ? Array.from([node]) : [];
Defensive patterns

Strategy: validation

Validate before calling

function toArray(value) {
  if (value == null) return [];
  if (Array.isArray(value)) return value.slice();
  if (typeof value.length === 'number') return Array.prototype.slice.call(value);
  return Array.from(value);
}

Type guard

function isArrayLike(value) {
  return value != null && typeof value !== 'function' && typeof value.length === 'number' && value.length >= 0;
}

Prevention

When it happens

Trigger: Calling Array.from(null), Array.from(undefined), or Array.from(value) where value is null/undefined at runtime, such as a missing DOM lookup (document.querySelector('#x') returns null) or a defaulted-out optional argument passed straight through.

Common situations: Converting a querySelector/All result or a JSON.parse result (which can be null) into an array without a null guard; calling Array.from(config.list) when config.list is absent; older browsers where the polyfill is the active code path.

Related errors


AI-assisted analysis of alvarotrigo/fullPage.js@49f15effa7 (2026-08-13). Data as JSON: /api/errors/d7d5edb1d0911508. Report an issue: GitHub.