sveltejs/kit · error · Error
Cannot access url.${property} on a page with prerendering en
Error message
Cannot access url.${property} on a page with prerendering enabled What it means
@sveltejs/kit's `disable_search` replaces the `search` and `searchParams` accessors on the request URL with getters that always throw, so code cannot read the query string during prerendering. Prerendered pages must be identical for every visitor, so the query string is meaningless; the library throws to surface accidental reliance on it instead of silently producing wrong output.
Source
Thrown at packages/kit/src/utils/url.js:204
get() {
throw new Error(
'Cannot access event.url.hash. Consider using `page.url.hash` inside a component instead'
);
}
});
}
/**
* Disallow access to `url.search` and `url.searchParams` during prerendering
* @param {URL} url
*/
export function disable_search(url) {
allow_nodejs_console_log(url);
for (const property of ['search', 'searchParams']) {
Object.defineProperty(url, property, {
get() {
throw new Error(`Cannot access url.${property} on a page with prerendering enabled`);
}
});
}
}
/**
* Allow URL to be console logged, bypassing disabled properties.
* @param {URL} url
*/
function allow_nodejs_console_log(url) {
if (!BROWSER) {
// @ts-ignore
url[Symbol.for('nodejs.util.inspect.custom')] = (_depth, opts, inspect) => {
return inspect(new URL(url), opts);
};
}
}
View on GitHub (pinned to 03f1687fe6)
Solutions
- Remove any read of `url.search`/`url.searchParams` from code paths that run during prerendering.
- Disable prerendering for routes that legitimately need the query string (`export const prerender = false`).
- Use page.url only for non-query parts (origin, pathname) in prerendered pages.
- Move query-string-dependent logic to client-side code or a server endpoint instead of the prerendered load.
Example fix
// before (prerendered route)
export function load({ url }) {
const token = url.searchParams.get('token');
return { token };
}
// after: make the route dynamic
export const prerender = false;
export function load({ url }) {
const token = url.searchParams.get('token');
return { token };
} Defensive patterns
Strategy: validation
Validate before calling
if (import.meta.env.SSR && should_prerender && (url.search || url.searchParams.size)) {
throw new Error('query string used in prerendered route');
} Type guard
function has_query(url) { return url.search.length > 0; } Try / catch
try {
const q = url.searchParams.get('page');
} catch {
const q = null; // prerendering: fall back to default
} Prevention
- Never read query params in load functions of prerendered routes
- Set `export const prerender = false` on query-dependent routes
- Audit shared load helpers for url.search/searchParams usage
- Use `url.pathname`/`origin` only in prerendered code
When it happens
Trigger: Accessing `url.search` or `url.searchParams` (directly or via helpers like `new URLSearchParams(url.search)`) inside load functions, page data, or handlers on a route being prerendered (`export const prerender = true` or global prerender config).
Common situations: Reading `?page=` or `?token=` from a URL in a prerendered page; calling `fetch(url)` with a URL object whose searchParams are read for cache-busting; sharing a load function between prerendered and dynamic routes without guarding query-string access.
Related errors
- Cannot call query '${__.name}' while prerendering, as preren
- Cannot call query.live '${__.name}' while prerendering, as p
- Cannot call query.batch '${__.name}' while prerendering, as
- ${keypath} option must be an absolute path, if specified. Se
- ${keypath} option must not end with '/'. See https://svelte.
AI-assisted analysis of sveltejs/kit@03f1687fe6 (2026-09-02).
Data as JSON: /api/errors/448e4bbd38a08818.
Report an issue: GitHub.