-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Description
Describe the bug
When calling a command from an API endpoint, the server throws a 500 error with the message Cannot call a command during server-side rendering
, even when ssr is set to false!
Calling a query works fine!
Reproduction
https://github.com/MAttila42/cannot-call-command-repro
Endpoints made in the repro:
GET http://localhost:5173/api/data
(works as intended)
POST http://localhost:5173/api/data
(throws the error mentioned)
POST http://localhost:5173/api/data/alternative
(first alternative - having the logic in a separate server function)
POST http://localhost:5173/api/data/alternative2
(second alternative - only using query functions)
The POST requests need a body like this:
{
"title": "test"
}
Logs
[500] POST /api/data
Error: Cannot call a command (`addData(...)`) during server-side rendering
at wrapper (node_modules\@sveltejs\kit\src\runtime\app\server\remote\command.js:68:10)
at POST (src\routes\api\data\+server.ts:12:9)
System Info
System:
OS: Windows 11 10.0.26100
CPU: (16) x64 12th Gen Intel(R) Core(TM) i7-12650H
Memory: 2.76 GB / 15.63 GB
Binaries (bun used):
Node: 24.6.0 - C:\Program Files\nodejs\node.EXE
npm: 11.5.1 - C:\Program Files\nodejs\npm.CMD
pnpm: 10.11.0 - ~\AppData\Roaming\npm\pnpm.CMD
bun: 1.2.20 - ~\AppData\Roaming\npm\bun.CMD
Browsers (none used):
Edge: Chromium (139.0.3405.111)
Internet Explorer: 11.0.26100.1882
npmPackages:
@sveltejs/adapter-auto: ^6.1.0 => 6.1.0
@sveltejs/kit: ^2.36.3 => 2.36.3
@sveltejs/vite-plugin-svelte: ^6.1.3 => 6.1.3
svelte: ^5.38.5 => 5.38.5
vite: ^7.1.3 => 7.1.3
Severity
blocking an upgrade
Additional Information
The reason why I'm doing this is because my project's not only present on the web, but also has an app counterpart. Following Rich Harris' advice I exposed a public endpoint that calls my remote functions.