alvarotrigo/fullPage.js · error · TypeError
predicate must be a function
Error message
predicate must be a function
What it means
Thrown by the Array.prototype.find polyfill (src/js/polyfills/array.find.js:17) at spec step 3, IsCallable(predicate). After the receiver is validated and length coerced, the polyfill checks typeof predicate !== 'function' and throws this message if the callback is not callable. The native method throws the same TypeError, so this polyfill path is only reached when Array.prototype.find is absent.
Source
Thrown at src/js/polyfills/array.find.js:17
// https://tc39.github.io/ecma262/#sec-array.prototype.find
if (!Array.prototype.find) {
Object.defineProperty(Array.prototype, 'find', {
value: function(predicate) {
// 1. Let O be ? ToObject(this value).
if (this == null) {
throw new TypeError('"this" is null or not defined');
}
var o = Object(this);
// 2. Let len be ? ToLength(? Get(O, "length")).
var len = o.length >>> 0;
// 3. If IsCallable(predicate) is false, throw a TypeError exception.
if (typeof predicate !== 'function') {
throw new TypeError('predicate must be a function');
}
// 4. If thisArg was supplied, let T be thisArg; else let T be undefined.
var thisArg = arguments[1];
// 5. Let k be 0.
var k = 0;
// 6. Repeat, while k < len
while (k < len) {
// a. Let Pk be ! ToString(k).
// b. Let kValue be ? Get(O, Pk).
// c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)).
// d. If testResult is true, return kValue.
var kValue = o[k];
if (predicate.call(thisArg, kValue, k, o)) {
return kValue;
}View on GitHub (pinned to 49f15effa7)
Solutions
- Pass a real function predicate: arr.find(item => item.active).
- If the predicate comes from config or an optional argument, default it or guard before calling: arr.find(predicate || (() => false)).
- Trace predicate back to its source and fix the assignment/import that produced a non-function.
- Verify the polyfill is active only on target browsers; on modern browsers the native find throws the equivalent error, so the fix is the same.
Example fix
// before
const match = items.find('id');
// predicate must be a function
// after
const match = items.find(item => item.id === 'id'); Defensive patterns
Strategy: validation
Validate before calling
function findWith(items, predicate) {
if (!Array.isArray(items)) {
throw new TypeError('expected an array');
}
if (typeof predicate !== 'function') {
throw new TypeError('predicate must be a function, got ' + typeof predicate);
}
return items.find(predicate);
} Type guard
const isFunction = (v) => typeof v === 'function'; // usage: if (isFunction(predicate)) items.find(predicate);
Prevention
- Treat the predicate as required input: assert typeof predicate === 'function' before the call.
- When the callback is optional from config, default it to a stable no-match function.
- Enable a linter rule (e.g., @typescript-eslint/no-unbound-method) to catch detached/invalid method references.
When it happens
Trigger: Calling arr.find() with no arguments; passing a non-function such as arr.find(null), arr.find(undefined), arr.find('name'), arr.find({}), or arr.find(someVar) where someVar resolved to a non-function value.
Common situations: Typo in a method name passed as the predicate; conditional code that omits the callback; reading a callback from config that is undefined when a feature flag is off; passing a property name string instead of a comparison function.
Related errors
- Array.from: when provided, the second argument must be a fun
- "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/06b9cb85c248f0d8.
Report an issue: GitHub.