sveltejs/kit · error
Cannot access event.${property} in a query. Pass the value a
Error message
Cannot access event.${property} in a query. Pass the value as an argument to the query instead What it means
Inside a remote `query` function, the request `event.url`, `event.params` and `event.route` properties are deliberately poisoned with throwing getters. SvelteKit requires query inputs to be explicit arguments so the query can be cached and re-run correctly on the client; reading request-bound state would make results non-deterministic. Pass the needed values as query arguments instead.
Source
Thrown at packages/kit/src/runtime/app/server/remote/shared.js:122
throw new Error('Cannot delete cookies in `query` or `prerender` functions');
}
if (opts.path && !opts.path.startsWith('/')) {
throw new Error('Cookies deleted in remote functions must have an absolute path');
}
return event.cookies.delete(name, opts);
}
}
};
if (state.is_in_remote_query) {
for (const property of ['url', 'params', 'route']) {
// non-enumerable so spreading for a nested derivation doesn't invoke the getter
Object.defineProperty(derived, property, {
enumerable: false,
get() {
throw new Error(
`Cannot access event.${property} in a query. Pass the value as an argument to the query instead`
);
}
});
}
}
return {
event: derived,
state: {
...state,
is_in_remote_function: true
}
};
}
/**
* Like `with_event` but removes things from `event` you cannot see/call in remote functions, such as `setHeaders`.View on GitHub (pinned to 03f1687fe6)
Solutions
- Pass the needed values explicitly as arguments to the query function, e.g. `query(async (slug) => ...)` and call it with `event.params.slug` from the client/caller
- Use `url`/`params` from the calling context (e.g. page state in `load` or the component) rather than the query's event
- If the value is constant per request, compute it outside the query and pass it in
Example fix
// before
export const getPost = query(async (event) => {
const post = await db.getPost(event.params.slug);
return post;
});
// after
export const getPost = query(async (slug) => {
const post = await db.getPost(slug);
return post;
});
// caller: getPost(event.params.slug) Defensive patterns
Strategy: type-guard
Validate before calling
// Never destructure request-bound properties inside a query body.
// Instead, extract needed values at the call site:
const { params, url } = event; // outside the query
const result = await myQuery(params.slug, url.searchParams.get('q')); Type guard
const canReadEventProp = (event, prop) => {
try { void event[prop]; return true; } catch { return false; }
}; Try / catch
try {
return await queryFn(event);
} catch (e) {
if (e.message.includes('Pass the value as an argument')) {
throw new Error('Refactor: pass event.url/params/route as query arguments');
}
throw e;
} Prevention
- Design query functions to take all request-derived values as arguments
- Avoid `...event` spreads or deep destructuring of the event inside remote queries
- Copy load-function code into queries only after stripping event.url/params/route access
When it happens
Trigger: Accessing `event.url`, `event.params`, or `event.route` (even via spread/destructuring that enumerates them is blocked, but direct access triggers it) inside a function created with `query(...)` while it executes in remote-query state.
Common situations: Migrating a `load` function to a remote `query` and keeping `const { params, url } = event`; building URLs from `event.url.origin` inside a query; reading route ids for conditional logic.
Related errors
- Cannot call query '${__.name}' while prerendering, as preren
- Cannot call '${__.name}.withOverride()' on the server
- requested(...) expects a query function created with query(.
- Query resolved without a value
- Could not get the request store.
AI-assisted analysis of sveltejs/kit@03f1687fe6 (2026-09-02).
Data as JSON: /api/errors/4fbf0d251508d16c.
Report an issue: GitHub.