sveltejs/kit · error
requested(...) expects a query function created with query(.
Error message
requested(...) expects a query function created with query(...), query.batch(...), or query.live(...)
What it means
requested() exposes results of queries tracked inside a command/form remote function, so the first argument must be a query function carrying internals of type query, query_batch, or query_live. Anything else fails this check.
Source
Thrown at packages/kit/src/runtime/app/server/remote/requested.js:114
* @template Input
* @template Output
* @template [Validated=Input]
* @param {RemoteQueryFunction<Input, Output, Validated> | RemoteLiveQueryFunction<Input, Output, Validated>} query
* @param {number} limit
* @returns {RequestedResult<Validated, Output>}
*/
export function requested(query, limit) {
const { event, state } = get_request_store();
const internals = /** @type {RemoteAnyQueryInternals | undefined} */ (
/** @type {any} */ (query).__
);
if (
internals?.type !== 'query' &&
internals?.type !== 'query_batch' &&
internals?.type !== 'query_live'
) {
throw new Error(
'requested(...) expects a query function created with query(...), query.batch(...), or query.live(...)'
);
}
// narrow-stable alias so generator closures below don't lose the narrowing
const __ = internals;
const requested = state.remote.requested;
const payloads = requested?.get(__.id) ?? new Set();
const ignored = (state.remote.ignored ??= new Set());
/** @param {string} payload */
const consume = (payload) => {
payloads.delete(payload);
if (payloads.size === 0) requested?.delete(__.id);
};
/** @param {string} payload */View on GitHub (pinned to 03f1687fe6)
Solutions
- Pass only functions created with query(...), query.batch(...), or query.live(...) to requested(...)
- Check imports so the correct query module is referenced
- If you need command results, read the command's return value directly instead of requested()
Example fix
// before const rows = await requested(myCommand, 5); // command, not query // after const rows = await requested(myQuery, 5);
Defensive patterns
Strategy: type-guard
Validate before calling
if (typeof fn !== 'function' || fn.__?.type !== 'query') {
throw new TypeError('expected a query() function');
} Type guard
function isQueryFn(fn) {
return typeof fn === 'function' &&
(fn.__?.type === 'query' || fn.__?.type === 'query_batch' || fn.__?.type === 'query_live');
} Try / catch
try {
const items = await requested(maybeQuery, 5);
} catch (e) {
if (!isQueryFn(maybeQuery)) throw new TypeError('pass a query() function');
throw e;
} Prevention
- Only pass query()/query.batch()/query.live() results to requested()
- Verify import paths for query modules
- Type-check arguments with JSDoc/TS
When it happens
Trigger: Passing a non-query function (a plain server function, command, form action, or arbitrary object) as the first argument to requested(...) inside a command/form.
Common situations: Typo importing the query; accidentally passing the command itself to requested(); calling requested() with an older module whose exports were refactored away from query().
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- Cannot call query '${__.name}' while prerendering, as preren
- Cannot call '${__.name}.withOverride()' on the server
- requested(...) can only be called in the context of a comman
- requested(${__.name}, ${limit}) cannot be used with synchron
- Skipping ${__.name}(${payload})
AI-assisted analysis of sveltejs/kit@03f1687fe6 (2026-09-02).
Data as JSON: /api/errors/337e8debb547fd30.
Report an issue: GitHub.