zloirock/core-js · error · TypeError
Object already initialized
Error message
Object already initialized
What it means
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.
Source
Thrown at packages/core-js/internals/internal-state.js:37
var getterFor = function (TYPE) {
return function (it) {
var state;
if (!isObject(it) || (state = get(it)).type !== TYPE) {
throw new TypeError('Incompatible receiver, ' + TYPE + ' required');
} return state;
};
};
if (NATIVE_WEAK_MAP || shared.state) {
var store = shared.state || (shared.state = new WeakMap());
/* eslint-disable no-self-assign -- prototype methods protection */
store.get = store.get;
store.has = store.has;
store.set = store.set;
/* eslint-enable no-self-assign -- prototype methods protection */
set = function (it, metadata) {
if (store.has(it)) throw new TypeError(OBJECT_ALREADY_INITIALIZED);
metadata.facade = it;
store.set(it, metadata);
return metadata;
};
get = function (it) {
return store.get(it) || {};
};
has = function (it) {
return store.has(it);
};
} else {
var STATE = sharedKey('state');
hiddenKeys[STATE] = true;
set = function (it, metadata) {
if (hasOwn(it, STATE)) throw new TypeError(OBJECT_ALREADY_INITIALIZED);
metadata.facade = it;
createNonEnumerableProperty(it, STATE, metadata);
return metadata;View on GitHub (pinned to 84e45fba09)
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.
Example fix
// before Map.call(existingMap); // TypeError: Object already initialized // after var fresh = new Map();
Defensive patterns
Strategy: try-catch
Validate before calling
// assume an internal `get` accessor is available for the same TYPE
if (Object.keys(internalGet(obj)).length > 0) { /* already initialized */ return; } Try / catch
try { internalSet(obj, metadata); } catch (e) { if (/Object already initialized/.test(e.message)) { metadata = internalGet(obj); } else throw e; } Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- ArrayBuffer expected
- Target is not a typed array
- Incompatible receiver, ${TYPE} required
- Cannot convert a Symbol value to a number
- Promise can't be resolved itself
AI-assisted analysis of zloirock/core-js@84e45fba09 (2026-08-30).
Data as JSON: /api/errors/c1daf2eaefb06613.
Report an issue: GitHub.