zloirock/core-js · error · TypeError
Incompatible receiver, ${TYPE} required
Error message
Incompatible receiver, ${TYPE} required What it means
core-js stores per-instance internal state via internal-state's set/get. getterFor(TYPE) returns an accessor that fetches the state and throws TypeError 'Incompatible receiver, <TYPE> required' when the receiver is not an object or its stored state's type differs from TYPE. It enforces that polyfilled prototype methods are only called on instances of the right class.
Source
Thrown at packages/core-js/internals/internal-state.js:24
var hasOwn = require('../internals/has-own-property');
var shared = require('../internals/shared-store');
var sharedKey = require('../internals/shared-key');
var hiddenKeys = require('../internals/hidden-keys');
var OBJECT_ALREADY_INITIALIZED = 'Object already initialized';
var TypeError = globalThis.TypeError;
var WeakMap = globalThis.WeakMap;
var set, get, has;
var enforce = function (it) {
return has(it) ? get(it) : set(it, {});
};
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) {View on GitHub (pinned to 84e45fba09)
Solutions
- Invoke methods on real instances: map.get(key), not extracted function references.
- Use .call(instance, ...) with a genuine instance when borrowing methods.
- Deduplicate core-js: ensure a single version/install of core-js in node_modules (check with npm ls core-js, dedupe).
- Don't mix native and polyfilled instances of the same class in one code path.
Example fix
// before
var get = new Map().get;
get('k'); // TypeError: Incompatible receiver, Map required
// after
var map = new Map();
map.get('k'); Defensive patterns
Strategy: type-guard
Validate before calling
function isMapLike(v){ return v instanceof Map || Object.prototype.toString.call(v) === '[object Map]'; }
if (!isMapLike(recv)) throw new TypeError('receiver must be a Map instance'); Type guard
function isInstanceOfType(v, TYPE){ return !!v && typeof v === 'object' && Object.prototype.toString.call(v) === '[object ' + TYPE + ']'; } Try / catch
try { method.apply(recv, args); } catch (e) { if (/Incompatible receiver/.test(e.message)) { bindMethodToCorrectInstance(); } else throw e; } Prevention
- Never detach polyfilled prototype methods; keep `this` bound to a real instance.
- Ensure exactly one core-js copy in the dependency tree (npm ls core-js / dedupe).
- Don't mix native and polyfilled instances of the same class.
- Use instance.method(...) directly instead of .call/.apply with ad-hoc receivers.
When it happens
Trigger: Calling a polyfilled method (Map/Set/WeakMap/Promise/DataView internals, etc.) with .call/.apply on a foreign object, calling a prototype method unbound so `this` is undefined, or mixing instances created by two different core-js copies (or core-js vs native) so state types don't match.
Common situations: Detached method references: const m = map.get; m(key); duplicate core-js installations from inconsistent dependency versions producing two internal-state registries; applying a polyfilled method to a native instance (or vice versa).
Related errors
- Target is not a typed array
- Object already initialized
- ArrayBuffer expected
- is not a typed array constructor
- Incorrect invocation
AI-assisted analysis of zloirock/core-js@84e45fba09 (2026-08-30).
Data as JSON: /api/errors/c78c4cefce2e9447.
Report an issue: GitHub.