sveltejs/kit · error · Error
Invalid data for Map reviver
Error message
Invalid data for Map reviver
What it means
When deserializing remote function arguments, a value tagged as a Map must be an array (of [key, value] string pairs). Anything else — an object, string, or non-array — indicates corrupted or forged payload data, so the reviver throws.
Source
Thrown at packages/kit/src/runtime/shared.js:182
};
}
const all_reducers = { ...encoders, ...remote_fns_reducers };
/** @type {(value: unknown) => string} */
const stringify = (value) => devalue.stringify(value, all_reducers);
return all_reducers;
}
function create_remote_arg_revivers() {
const remote_fns_revivers = {
/** @type {(value: unknown) => unknown} */
[remote_object]: (value) => value,
/** @type {(value: unknown) => Map<unknown, unknown>} */
[remote_map]: (value) => {
if (!Array.isArray(value)) {
throw new Error('Invalid data for Map reviver');
}
const map = new Map();
for (const item of value) {
if (
!Array.isArray(item) ||
item.length !== 2 ||
typeof item[0] !== 'string' ||
typeof item[1] !== 'string'
) {
throw new Error('Invalid data for Map reviver');
}
const [key, val] = item;
map.set(parse(key), parse(val));
}
return map;View on GitHub (pinned to 03f1687fe6)
Solutions
- Send Map arguments through the standard remote-function client (don't hand-build request bodies)
- Update @sveltejs/kit on client and server so serialization versions match
- If testing, mock at the function level rather than reshaping the wire format
Defensive patterns
Strategy: type-guard
Validate before calling
function isValidMapPayload(v) { return Array.isArray(v); } Type guard
function isMapWireFormat(v) {
return Array.isArray(v) && v.every((e) => Array.isArray(e) && e.length === 2 && typeof e[0] === 'string' && typeof e[1] === 'string');
} Try / catch
try {
const result = await remoteFn(args);
} catch (e) {
if (e.message.includes('Map reviver')) console.error('Malformed Map argument payload — resend via official client');
} Prevention
- Use the official remote-function client to serialize Maps
- Don't hand-craft or mutate remote request bodies
- Keep client and server @sveltejs/kit versions in sync
When it happens
Trigger: A request payload where the remote_map-tagged value is not an array; hand-crafted or middleware-mutated request bodies; version mismatch between client serializer and server reviver.
Common situations: Proxies or test harnesses re-serializing request JSON incorrectly; custom fetch mocks returning reshaped arguments to remote functions.
Related errors
- Multiple values provided for ${name} header where only one e
- The ${protocol_header} header specified ${protocol} which is
- The ${port_header} header specified ${port} which is an inva
- The `csp.directives['trusted-types']` option must include 's
- Could not get the request store.
AI-assisted analysis of sveltejs/kit@03f1687fe6 (2026-09-02).
Data as JSON: /api/errors/7b7a4bcc087e80b1.
Report an issue: GitHub.