sveltejs/kit · error
Redirects are not allowed in commands. Return a result inste
Error message
Redirects are not allowed in commands. Return a result instead and use goto on the client
What it means
Remote commands run on the server but execute through the client runtime; returning a redirect response from a command is unsupported because the client would need to perform a full navigation mid-command. Instead, commands must return a result and let the client decide to call goto().
Source
Thrown at packages/kit/src/runtime/client/remote-functions/command.svelte.js:67
if (updates_error) {
throw updates_error;
}
const response = await remote_request(
`${base}/${app_dir}/remote/${id}`,
{
method: 'POST',
body: JSON.stringify({
payload: await stringify_command_arg(arg),
refreshes: Array.from(refreshes ?? [])
}),
headers
},
refreshes
);
if (response.redirect) {
throw new Error(
'Redirects are not allowed in commands. Return a result instead and use goto on the client'
);
}
fail_unhandled_refreshes(refreshes);
return response._;
} finally {
overrides?.forEach((fn) => fn());
// Decrement pending count when command completes
pending_count--;
}
})()
);
let updates_called = false;
promise.updates = (...args) => {View on GitHub (pinned to 03f1687fe6)
Solutions
- Return a normal result (e.g. { success: true, redirectTo: '/dash' }) from the command
- Call goto(result.redirectTo) in the client after awaiting the command
- Move flows that genuinely need redirects back to form actions/+page.server.js
Example fix
// before
// command server handler
return redirect(303, '/dashboard');
// after
return { ok: true, redirectTo: '/dashboard' };
// client
const res = await createAccount(...);
if (res.redirectTo) goto(res.redirectTo); Defensive patterns
Strategy: try-catch
Validate before calling
// server side: never call redirect() inside a command handler
function assertNoRedirect(result) {
if (result && result.redirect) throw new Error('commands cannot redirect; return data instead');
return result;
} Try / catch
try { const res = await myCommand(...); } catch (e) { if (e.message.includes('Redirects are not allowed in commands')) { /* restructure to result + client goto */ } else { throw e; } } Prevention
- Design commands to return plain serializable results
- Handle post-command routing exclusively on the client with goto
- Reserve redirect() for form actions and load functions
When it happens
Trigger: A remote command function whose server handler returns redirect(...) (or sets response.redirect); the client wrapper detects response.redirect after the RPC completes and throws.
Common situations: Porting form-action or endpoint code that used `redirect()` into remote commands; post-login redirects implemented server-side; copying +page.server.js patterns into .remote.ts commands.
Related errors
- Invalid status code
- Could not get the request store.
- Cannot export `default` from a remote module (${file}) — ple
- `${name}` exported from ${file} is invalid — all exports fro
- Invalid redirect location ${JSON.stringify(location)}: this
AI-assisted analysis of sveltejs/kit@03f1687fe6 (2026-09-02).
Data as JSON: /api/errors/0c886db63902908f.
Report an issue: GitHub.