alvarotrigo/fullPage.js · error · TypeError

Cannot convert undefined or null to object

Error message

Cannot convert undefined or null to object

What it means

Thrown by the Object.assign polyfill (src/js/polyfills/object.assign.js:9) before the loop begins: the target (first argument) must be coercible to an object via Object(target), and null/undefined cannot be coerced, so the polyfill throws this TypeError. Note that source arguments (index >= 1) are explicitly skipped when null/undefined (the nextSource != null guard in the loop); only the target triggers this error.

Source

Thrown at src/js/polyfills/object.assign.js:9

if (typeof Object.assign != 'function') {
    // Must be writable: true, enumerable: false, configurable: true
    Object.defineProperty(Object, 'assign', {
        value: function assign(target, varArgs) {
            // .length of function is 2
            'use strict';
            if (target == null) {
                // TypeError if undefined or null
                throw new TypeError(
                    'Cannot convert undefined or null to object'
                );
            }

            var to = Object(target);

            for (var index = 1; index < arguments.length; index++) {
                var nextSource = arguments[index];

                if (nextSource != null) {
                    // Skip over if undefined or null
                    for (var nextKey in nextSource) {
                        // Avoid bugs when hasOwnProperty is shadowed
                        if (
                            Object.prototype.hasOwnProperty.call(
                                nextSource,
                                nextKey
                            )

View on GitHub (pinned to 49f15effa7)

Solutions

  1. Default the target to a fresh object: Object.assign(target || {}, source).
  2. Give the receiving parameter an explicit default: function merge(target = {}) { return Object.assign(target, ...sources); }.
  3. Validate that target is an object before calling: if (target && typeof target === 'object') Object.assign(target, source).
  4. Fix the upstream code that produced null/undefined for the target instead of silently substituting it.

Example fix

// before
function configure(opts) {
  return Object.assign(opts, defaults);
}
configure(); // Cannot convert undefined or null to object

// after
function configure(opts = {}) {
  return Object.assign(opts, defaults);
}
Defensive patterns

Strategy: validation

Validate before calling

function assignSafe(target) {
  var t = (target == null) ? {} : Object(target);
  for (var i = 1; i < arguments.length; i++) {
    var src = arguments[i];
    if (src != null) Object.assign(t, src);
  }
  return t;
}

Type guard

const isObject = (v) => v != null && (typeof v === 'object' || typeof v === 'function');
// usage: if (isObject(target)) Object.assign(target, src);

Prevention

When it happens

Trigger: Calling Object.assign(null, src), Object.assign(undefined, src), or Object.assign() with no arguments at all; passing a config/target variable that resolved to null or undefined as the first argument.

Common situations: Passing an options object that was never initialized (e.g., a function param with no default); spreading defaults onto a target that an upstream call returned null for; legacy browsers where the polyfill is the active path.

Related errors


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