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 that

View on GitHub (pinned to 03f1687fe6)

Solutions

  1. Check proxy/server body size limits and raise them if large files are truncated
  2. Align @sveltejs/kit versions and rebuild both client and server bundles
  3. Send Files through the official remote-function client (do not pre-convert to JSON or FormData yourself)
  4. 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

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


AI-assisted analysis of sveltejs/kit@03f1687fe6 (2026-09-02). Data as JSON: /api/errors/5ecf899ea3b6e9ae. Report an issue: GitHub.