{"record":{"id":"c1daf2eaefb06613","repo":"zloirock/core-js","slug":"object-already-initialized","errorCode":null,"errorMessage":"Object already initialized","messagePattern":"Object already initialized","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/core-js/internals/internal-state.js","lineNumber":37,"sourceCode":"\nvar getterFor = function (TYPE) {\n  return function (it) {\n    var state;\n    if (!isObject(it) || (state = get(it)).type !== TYPE) {\n      throw new TypeError('Incompatible receiver, ' + TYPE + ' required');\n    } return state;\n  };\n};\n\nif (NATIVE_WEAK_MAP || shared.state) {\n  var store = shared.state || (shared.state = new WeakMap());\n  /* eslint-disable no-self-assign -- prototype methods protection */\n  store.get = store.get;\n  store.has = store.has;\n  store.set = store.set;\n  /* eslint-enable no-self-assign -- prototype methods protection */\n  set = function (it, metadata) {\n    if (store.has(it)) throw new TypeError(OBJECT_ALREADY_INITIALIZED);\n    metadata.facade = it;\n    store.set(it, metadata);\n    return metadata;\n  };\n  get = function (it) {\n    return store.get(it) || {};\n  };\n  has = function (it) {\n    return store.has(it);\n  };\n} else {\n  var STATE = sharedKey('state');\n  hiddenKeys[STATE] = true;\n  set = function (it, metadata) {\n    if (hasOwn(it, STATE)) throw new TypeError(OBJECT_ALREADY_INITIALIZED);\n    metadata.facade = it;\n    createNonEnumerableProperty(it, STATE, metadata);\n    return metadata;","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/zloirock/core-js/blob/84e45fba098dd3a177d5cf2247d06ab8e98d3790/packages/core-js/internals/internal-state.js#L19-L55","documentation":"internal-state.set attaches metadata to an object via a WeakMap-backed store; if the object already has metadata (store.has(it)), it throws TypeError 'Object already initialized' (OBJECT_ALREADY_INITIALIZED). This protects the invariant that internal state is set exactly once per instance, e.g. by a polyfilled constructor.","triggerScenarios":"Calling the internal set() twice on the same object — re-running a polyfilled constructor against an existing instance (e.g. Reflect.construct or .call-ing the constructor on an instance), double-initialization during subclassing tricks, or two core-js copies sharing one store but with differing type expectations.","commonSituations":"Constructor-invocation hacks: Map.call(existingMap); patching/re-initializing polyfilled collections; test code resetting instances by re-invoking constructors; module duplication causing two initializers for one object.","solutions":["Construct fresh instances instead of re-invoking constructors on existing objects.","Guard: call set/initialization only once per object (check get(it) first).","Deduplicate core-js versions so only one internal-state registry initializes objects.","If you must reinitialize, create a new instance and copy data rather than re-running the constructor."],"exampleFix":"// before\nMap.call(existingMap); // TypeError: Object already initialized\n// after\nvar fresh = new Map();","handlingStrategy":"try-catch","validationCode":"// assume an internal `get` accessor is available for the same TYPE\nif (Object.keys(internalGet(obj)).length > 0) { /* already initialized */ return; }","typeGuard":null,"tryCatchPattern":"try { internalSet(obj, metadata); } catch (e) { if (/Object already initialized/.test(e.message)) { metadata = internalGet(obj); } else throw e; }","preventionTips":["Initialize internal state exactly once per object, at construction.","Never re-invoke polyfilled constructors on existing instances (e.g. Map.call(x)).","Create a fresh instance instead of re-initializing.","Deduplicate core-js so a single internal-state registry owns initialization."],"tags":["typeerror","internal-state","double-initialization","polyfill"],"backgroundTag":"object-already-initialized","analyzedSha":"84e45fba098dd3a177d5cf2247d06ab8e98d3790","analyzedAt":"2026-08-30T20:36:10.323Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}