alvarotrigo/fullPage.js · error · TypeError
Array.from: when provided, the second argument must be a fun
Error message
Array.from: when provided, the second argument must be a function
What it means
Thrown by the Array.from polyfill (src/js/polyfills/array.from.js:49) at spec step 5a. When the second argument (mapFn) is provided (i.e. arguments.length > 1 and the value is not undefined), the polyfill runs isCallable(mapFn); if it is not a function, this TypeError is thrown. The native Array.from produces the same error.
Source
Thrown at src/js/polyfills/array.from.js:49
// 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) {
T = arguments[2];
}
}
// 10. Let lenValue be Get(items, "length").
// 11. Let len be ToLength(lenValue).
var len = toLength(items.length);
// 13. If IsConstructor(C) is true, then
// 13. a. Let A be the result of calling the [[Construct]] internal method
// of C with an argument list containing the single item len.
// 14. a. Else, Let A be ArrayCreate(len).View on GitHub (pinned to 49f15effa7)
Solutions
- Pass a real function as the second argument: Array.from(items, x => x.id).
- If you only need conversion with no mapping, omit the second argument entirely.
- Conditionally pass the mapper only when it is a function: Array.from(items, typeof mapper === 'function' ? mapper : undefined).
- Validate the value at its source and fix the assignment that produced a non-function.
Example fix
// before const ids = Array.from(rows, 'id'); // Array.from: when provided, the second argument must be a function // after const ids = Array.from(rows, row => row.id);
Defensive patterns
Strategy: type-guard
Validate before calling
function fromWith(items, mapFn) {
return Array.isArray(items) ? items.slice() : Array.from(items, typeof mapFn === 'function' ? mapFn : undefined);
} Type guard
const isCallable = (v) => typeof v === 'function'; // usage: Array.from(items, isCallable(mapFn) ? mapFn : undefined);
Prevention
- Only pass mapFn when it is genuinely a function; otherwise omit the argument.
- Coerce optional mappers: typeof mapper === 'function' ? mapper : undefined before the call.
- Avoid passing positional placeholders (null/0/strings) where a mapper is expected.
When it happens
Trigger: Calling Array.from(items, 5), Array.from(items, 'toString'), Array.from(items, null), or Array.from(items, mapper) where mapper is not a function; passing an optional third positional by mistake into the second slot.
Common situations: Reading a mapper from config that is undefined when disabled but still passed positionally; passing a string method name instead of a bound function; a refactor that changed a function value into something else without updating the call site.
Related errors
- predicate must be a function
- "this" is null or not defined
- Array.from requires an array-like object - not null or undef
- Cannot convert undefined or null to object
AI-assisted analysis of alvarotrigo/fullPage.js@49f15effa7 (2026-08-13).
Data as JSON: /api/errors/5ecadeaf7c570681.
Report an issue: GitHub.