immutable-js/immutable-js · error · Error
Can not call `Record` with an immutable Record as default va
Error message
Can not call `Record` with an immutable Record as default values. Use a plain javascript object instead.
What it means
Record defaults must be a plain object; any other immutable Collection (Map, List, Seq, Set, etc.) is rejected. Immutable cannot use a Collection as a defaults template because defaults are copied per-field into plain properties.
Source
Thrown at src/Record.js:28
import { getIn } from './methods/getIn';
import { merge, mergeWith } from './methods/merge';
import { mergeDeep, mergeDeepWith } from './methods/mergeDeep';
import { mergeDeepIn } from './methods/mergeDeepIn';
import { mergeIn } from './methods/mergeIn';
import { setIn } from './methods/setIn';
import { update } from './methods/update';
import { updateIn } from './methods/updateIn';
import { withMutations } from './methods/withMutations';
import { isImmutable } from './predicates/isImmutable';
import { IS_RECORD_SYMBOL, isRecord } from './predicates/isRecord';
import { toJS } from './toJS';
import invariant from './utils/invariant';
import quoteString from './utils/quoteString';
function throwOnInvalidDefaultValues(defaultValues) {
if (isRecord(defaultValues)) {
throw new Error(
'Can not call `Record` with an immutable Record as default values. Use a plain javascript object instead.'
);
}
if (isImmutable(defaultValues)) {
throw new Error(
'Can not call `Record` with an immutable Collection as default values. Use a plain javascript object instead.'
);
}
if (defaultValues === null || typeof defaultValues !== 'object') {
throw new Error(
'Can not call `Record` with a non-object as default values. Use a plain javascript object instead.'
);
}
}
export class Record {View on GitHub (pinned to 59fdaae676)
Solutions
- Convert to plain object: Record(map.toObject()) or Record(fromJS(obj).toJS())
- Build defaults with a plain object literal or Object.fromEntries(map.entrySeq())
- If you want a Record with dynamic keys, use a Map instead — Records require a fixed key set
Example fix
// before
const R = Record(Immutable.Map({ a: 1 })); // throws
// after
const R = Record({ a: 1 }); Defensive patterns
Strategy: type-guard
Validate before calling
import { isImmutable, isCollection } from 'immutable';
function plainDefaults(v) {
return isImmutable(v) ? v.toObject() : v;
} Type guard
const isPlainObj = (v: unknown): v is Record<string, unknown> => !!v && typeof v === 'object' && !Array.isArray(v) && !isImmutable(v);
Prevention
- Convert Map/Set/Seq defaults with .toObject()/.toJS() first
- Keep a helper toPlain(v) used before all Record() calls
When it happens
Trigger: Record(Immutable.Map({ a: 1 })) or Record(someList) — passing any immutable Collection where the defaults object is expected.
Common situations: Building Record defaults dynamically from an existing Map or fromJS() output; refactoring code where a Map was previously spread into a plain object.
Related errors
- Expected [K, V] tuple: {}
- Can not call `Record` with an immutable Collection as defaul
- Value type {} cannot be hashed.
- Can not call `Record` with a non-object as default values. U
- Cannot define {} with property "{}" since that property name
AI-assisted analysis of immutable-js/immutable-js@59fdaae676 (2026-08-27).
Data as JSON: /api/errors/b4d6cf32272792e6.
Report an issue: GitHub.