alvarotrigo/fullPage.js · error · TypeError

"this" is null or not defined

Error message

"this" is null or not defined

What it means

Thrown by the Array.prototype.find polyfill (src/js/polyfills/array.find.js:7) during spec step 1, which coerces the receiver to an object via ToObject(this). When the method is invoked with a this value of null or undefined, ToObject cannot coerce it and the polyfill surfaces the failure as this explicit TypeError. The native ES6 implementation throws the identical error, so this only runs on browsers lacking Array.prototype.find.

Source

Thrown at src/js/polyfills/array.find.js:7

// 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;

View on GitHub (pinned to 49f15effa7)

Solutions

  1. Ensure find is called as a member of an actual array: arr.find(predicate).
  2. If invoking indirectly, bind the receiver: const f = arr.find.bind(arr); f(predicate) or Array.prototype.find.call(arr, predicate).
  3. If the array may be missing, guard the call site with optional chaining or a null check: (arr && Array.isArray(arr)) ? arr.find(predicate) : undefined.
  4. Confirm the polyfill is even needed: if Array.prototype.find exists natively, a null receiver still throws natively, so the root cause is the receiver, not the polyfill.

Example fix

// before
const find = list.find;
find(isActive); // "this" is null or not defined

// after
list.find(isActive);
// or, if indirect call is required:
const find = list.find.bind(list);
find(isActive);
Defensive patterns

Strategy: type-guard

Validate before calling

function safeFind(arr, predicate, thisArg) {
  if (arr == null || !Array.isArray(arr)) {
    return undefined;
  }
  if (typeof predicate !== 'function') {
    throw new TypeError('predicate must be a function');
  }
  return Array.prototype.find.call(arr, predicate, thisArg);
}

Type guard

function isArrayLike(value) {
  return value != null && typeof value !== 'boolean' && typeof value !== 'number' && typeof value[Symbol.iterator] === 'function' || (typeof value === 'object' && Number.isFinite(Number(value.length)));
}

Prevention

When it happens

Trigger: Invoking the find polyfill on a null/undefined receiver: Array.prototype.find.call(null, fn) or .call(undefined, fn); detaching the method reference so this is undefined in non-strict scope (const f = arr.find; f(fn)); or calling a stored/aliased copy of find without rebinding it to an array.

Common situations: Saving a method reference in a variable, callback, or decorator and invoking it bare so this is lost; spread/destructure bugs that resolve the array to null/undefined; old browsers (IE11 and earlier) where the polyfill is active and code assumed a real array was present.

Related errors


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