{"record":{"id":"285a0c53f1637632","repo":"alvarotrigo/fullPage.js","slug":"cannot-convert-undefined-or-null-to-object","errorCode":null,"errorMessage":"Cannot convert undefined or null to object","messagePattern":"Cannot convert undefined or null to object","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/js/polyfills/object.assign.js","lineNumber":9,"sourceCode":"if (typeof Object.assign != 'function') {\n    // Must be writable: true, enumerable: false, configurable: true\n    Object.defineProperty(Object, 'assign', {\n        value: function assign(target, varArgs) {\n            // .length of function is 2\n            'use strict';\n            if (target == null) {\n                // TypeError if undefined or null\n                throw new TypeError(\n                    'Cannot convert undefined or null to object'\n                );\n            }\n\n            var to = Object(target);\n\n            for (var index = 1; index < arguments.length; index++) {\n                var nextSource = arguments[index];\n\n                if (nextSource != null) {\n                    // Skip over if undefined or null\n                    for (var nextKey in nextSource) {\n                        // Avoid bugs when hasOwnProperty is shadowed\n                        if (\n                            Object.prototype.hasOwnProperty.call(\n                                nextSource,\n                                nextKey\n                            )","sourceCodeStart":1,"sourceCodeEnd":27,"githubUrl":"https://github.com/alvarotrigo/fullPage.js/blob/49f15effa7b195def295a36f872c28153cf9fb00/src/js/polyfills/object.assign.js#L1-L27","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Default the target to a fresh object: Object.assign(target || {}, source).","Give the receiving parameter an explicit default: function merge(target = {}) { return Object.assign(target, ...sources); }.","Validate that target is an object before calling: if (target && typeof target === 'object') Object.assign(target, source).","Fix the upstream code that produced null/undefined for the target instead of silently substituting it."],"exampleFix":"// before\nfunction configure(opts) {\n  return Object.assign(opts, defaults);\n}\nconfigure(); // Cannot convert undefined or null to object\n\n// after\nfunction configure(opts = {}) {\n  return Object.assign(opts, defaults);\n}","handlingStrategy":"validation","validationCode":"function assignSafe(target) {\n  var t = (target == null) ? {} : Object(target);\n  for (var i = 1; i < arguments.length; i++) {\n    var src = arguments[i];\n    if (src != null) Object.assign(t, src);\n  }\n  return t;\n}","typeGuard":"const isObject = (v) => v != null && (typeof v === 'object' || typeof v === 'function');\n// usage: if (isObject(target)) Object.assign(target, src);","tryCatchPattern":null,"preventionTips":["Give target parameters an explicit default: function merge(target = {}) { ... }.","Coerce before calling: Object.assign(target || {}, source).","Remember only the target throws here; null/undefined sources are silently skipped, which can hide bugs — log when a source is skipped if its data matters."],"tags":["polyfill","object","null-check","es2015","arguments"],"backgroundTag":null,"analyzedSha":"49f15effa7b195def295a36f872c28153cf9fb00","analyzedAt":"2026-08-13T04:33:34.972Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}