sveltejs/kit · error · Error

a load function ${location_description} returned ${typeof da

Error message

a load function ${location_description} returned ${typeof data !== 'object' ? `a ${typeof data}` : data instanceof Response ? 'a Response object' : Array.isArray(data) ? 'an array' : 'a non-plain object'}

What it means

Load functions (+page.js/.server.js, +layout.js/.server.js) must return a plain object (or undefined). validate_load_response rejects primitives, arrays, Response objects, and class instances because the serialized load data contract expects plain JSON-able objects.

Source

Thrown at packages/kit/src/runtime/shared.js:28

	const match = /^(moz-icon|view-source|jar):/.exec(dep);
	if (match) {
		console.warn(
			`${route_id}: Calling \`depends('${dep}')\` will throw an error in Firefox because \`${match[1]}\` is a special URI scheme`
		);
	}
}

export const INVALIDATED_PARAM = 'x-sveltekit-invalidated';

export const TRAILING_SLASH_PARAM = 'x-sveltekit-trailing-slash';

/**
 * @param {any} data
 * @param {string} [location_description]
 */
export function validate_load_response(data, location_description) {
	if (data != null && Object.getPrototypeOf(data) !== Object.prototype) {
		throw new Error(
			`a load function ${location_description} returned ${
				typeof data !== 'object'
					? `a ${typeof data}`
					: data instanceof Response
						? 'a Response object'
						: Array.isArray(data)
							? 'an array'
							: 'a non-plain object'
			}, but must return a plain object at the top level (i.e. \`return {...}\`)`
		);
	}
}

const object_proto_names = /* @__PURE__ */ Object.getOwnPropertyNames(Object.prototype)
	.sort()
	.join('\0');

/**

View on GitHub (pinned to 03f1687fe6)

Solutions

  1. Return a plain object: { items: [...] } instead of the raw array or Response
  2. If you need the raw Response semantics, use the response's json()/text() and spread into an object
  3. Check class instances — serialize to plain objects (JSON.parse(JSON.stringify(x)) or explicit mapping)

Example fix

// before
export async function load({ fetch }) {
  return fetch('/api/items'); // Response object
}
// after
export async function load({ fetch }) {
  const res = await fetch('/api/items');
  return { items: await res.json() };
}
Defensive patterns

Strategy: type-guard

Validate before calling

function isPlainObject(v) {
  return v == null || Object.getPrototypeOf(v) === Object.prototype;
}
// assert isPlainObject(result) before returning from load

Type guard

function isPlainObject(v) {
  return v !== null && typeof v === 'object' && Object.getPrototypeOf(v) === Object.prototype;
}

Prevention

When it happens

Trigger: return fetch(url) (a Response) instead of return { ...(await res.json()) } or fetch with load's built-in fetch; returning an array directly; returning new Date() or a class instance; returning a string/number.

Common situations: Migrating from SvelteKit versions where returning a Response from load was allowed; accidental `return data.map(...)` at the wrong level; wrapping data in a Map/Set.

Related errors


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