ajaxorg/ace · error · TypeError
Cannot convert undefined or null to object
Error message
Cannot convert undefined or null to object
What it means
This TypeError is thrown by the ES6-shim polyfill for Object.assign when the first argument (target) is undefined or null. Per the ES6 spec, Object.assign cannot coerce null/undefined into an object, so the shim mimics native behavior and fails fast with this exact message.
Source
Thrown at src/lib/es6-shim.js:51
var result = "";
var string = this;
while (count > 0) {
if (count & 1) result += string;
if ((count >>= 1)) string += string;
}
return result;
});
}
if (!String.prototype.includes) {
defineProp(String.prototype, "includes", function (str, position) {
return this.indexOf(str, position) != -1;
});
}
if (!Object.assign) {
Object.assign = function (target) {
if (target === undefined || target === null) {
throw new TypeError("Cannot convert undefined or null to object");
}
var output = Object(target);
for (var index = 1; index < arguments.length; index++) {
var source = arguments[index];
if (source !== undefined && source !== null) {
Object.keys(source).forEach(function (key) {
output[key] = source[key];
});
}
}
return output;
};
}
if (!Object.values) {
Object.values = function (o) {
return Object.keys(o).map(function (k) {
return o[k];View on GitHub (pinned to 2c1eddc392)
Solutions
- Ensure the target argument is a non-null object before calling Object.assign, or default it: Object.assign(target || {}, src)
- Fix the upstream code that produced the null/undefined target instead of papering over it at the call site
- If null targets are intentional no-ops in your logic, switch to a helper like {...target, ...src} or a merge utility that skips null targets
- On modern engines verify Object.assign is native (not this shim) — the native one throws the same TypeError, so the root fix is identical
Example fix
// before
Object.assign(userPrefs, defaults); // userPrefs undefined on first run
// after
Object.assign(userPrefs || {}, defaults); Defensive patterns
Strategy: type-guard
Validate before calling
if (target == null) throw new TypeError('Object.assign requires a non-null target');
Object.assign(target, source); Type guard
function isMergeTarget(t) { return t !== null && (typeof t === 'object' || typeof t === 'function'); } Try / catch
try {
return Object.assign(target, src);
} catch (e) {
if (e instanceof TypeError) return Object.assign({}, src); // or rethrow
throw e;
} Prevention
- Default target arguments: Object.assign(target || {}, src)
- Enable null-safety lint rules or TypeScript non-null assertions on merge targets
- Don't pass results of possibly-empty lookups (Map.get, querySelector) straight into Object.assign
When it happens
Trigger: Calling Object.assign(null, {...}) or Object.assign(undefined, {...}) — typically when a variable expected to hold a target object is uninitialized or a lookup returned null.
Common situations: Running code on legacy browsers (IE) or old JS engines lacking native Object.assign, where the es6-shim polyfill is active; passing the result of a failed lookup (e.g., map.get or DOM query) as the merge target.
AI-assisted analysis of ajaxorg/ace@2c1eddc392 (2026-08-30).
Data as JSON: /api/errors/0df4957952d23b45.
Report an issue: GitHub.