sveltejs/kit · error · Error
Invalid data for File reviver
Error message
Invalid data for File reviver
What it means
File objects sent to remote functions are encoded as { data (ArrayBuffer), name, type, size, lastModified }. On the server, the File reviver validates every field before reconstructing a File. If any field is missing or of the wrong type, Kit throws this error instead of creating an invalid File.
Source
Thrown at packages/kit/src/runtime/shared.js:230
throw new Error('Invalid data for Set reviver');
}
set.add(parse(item));
}
return set;
},
/** @type {(value: any) => File} */
[remote_file]: (value) => {
if (
!value ||
typeof value !== 'object' ||
typeof value.name !== 'string' ||
typeof value.type !== 'string' ||
typeof value.size !== 'number' ||
typeof value.lastModified !== 'number' ||
!(value.data instanceof ArrayBuffer)
) {
throw new Error('Invalid data for File reviver');
}
const { data, name, ...meta } = value;
return new File([data], name, meta);
}
};
const all_revivers = { ...decoders, ...remote_fns_revivers };
/** @type {(data: string) => unknown} */
const parse = (data) => devalue.parse(data, all_revivers);
return all_revivers;
}
/**
* Stringifies the argument (if any) for a remote function in such a way thatView on GitHub (pinned to 03f1687fe6)
Solutions
- Check proxy/server body size limits and raise them if large files are truncated
- Align @sveltejs/kit versions and rebuild both client and server bundles
- Send Files through the official remote-function client (do not pre-convert to JSON or FormData yourself)
- Verify no middleware reads/re-parses the request body before Kit handles it
Example fix
// before (converting the File yourself)
await save({ file: { name: f.name, data: await f.arrayBuffer() } });
// after (pass the File directly)
await save({ file }); Defensive patterns
Strategy: validation
Validate before calling
function isEncodableFile(f) {
return f instanceof File &&
typeof f.name === 'string' && typeof f.type === 'string' &&
Number.isFinite(f.size) && Number.isFinite(f.lastModified);
}
if (!isEncodableFile(file)) throw new Error('Not a valid File to send to a remote function'); Type guard
const isFile = (v) => typeof File !== 'undefined' && v instanceof File && typeof v.name === 'string' && typeof v.size === 'number';
Try / catch
try {
await uploadFile(file);
} catch (e) {
if (/Invalid data for File reviver/.test(e?.message ?? '')) {
alert('Upload failed — the file payload was truncated or malformed. Check body size limits.');
} else throw e;
} Prevention
- Raise proxy body-size limits (e.g. nginx client_max_body_size) for uploads
- Pass File objects directly to remote functions, never pre-serialized JSON
- Align Kit versions across client and server
- Keep file metadata intact — don't reconstruct partial File-like objects
When it happens
Trigger: Calling a remote function with a File argument when the decoded payload lacks/wrongly types name, type, size, lastModified, or data — e.g. request body truncated, multipart/JSON bodies hand-assembled incorrectly, or client/server serialization versions mismatched.
Common situations: Large uploads cut off by proxy body-size limits (nginx client_max_body_size, platform limits); custom fetch wrappers that re-serialize the body; stale cached client code after upgrading Kit.
Related errors
- Regular expressions are not valid remote function arguments
- Invalid data for Set reviver
- Promises are not valid remote function arguments
- Could not get the request store.
- Cannot export `default` from a remote module (${file}) — ple
AI-assisted analysis of sveltejs/kit@03f1687fe6 (2026-09-02).
Data as JSON: /api/errors/5ecf899ea3b6e9ae.
Report an issue: GitHub.