{"record":{"id":"81e809e1e8ce7f66","repo":"sveltejs/kit","slug":"cannot-call-name-parens-on-the-server","errorCode":null,"errorMessage":"Cannot call `${name}${parens}` on the server","messagePattern":"Cannot call `(.+?)(.+?)` on the server","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/kit/src/utils/functions.js","lineNumber":26,"sourceCode":"\tlet done = false;\n\n\t/** @type T */\n\tlet result;\n\n\treturn () => {\n\t\tif (done) return result;\n\t\tdone = true;\n\t\treturn (result = fn());\n\t};\n}\n\n/**\n * @param {string} name\n * @param {string} [parens]\n */\nexport function disallow_on_server(name, parens = '(...)') {\n\treturn () => {\n\t\tthrow new Error(`Cannot call \\`${name}${parens}\\` on the server`);\n\t};\n}\n","sourceCodeStart":8,"sourceCodeEnd":29,"githubUrl":"https://github.com/sveltejs/kit/blob/03f1687fe612ce3d2d9131139b5b188d9cf90c64/packages/kit/src/utils/functions.js#L8-L29","documentation":"Several $app/navigation APIs (goto, invalidate, invalidateAll, refreshAll, applyAction, disableScrollHandling) only make sense in the browser. When SvelteKit's module is loaded on the server, those functions are stubs that throw this error, so developers get a clear message instead of confusing server-side behavior.","triggerScenarios":"Calling goto/invalidate/invalidateAll/refreshAll/applyAction/disableScrollHandling inside code that runs during SSR: top-level of +page.js/+layout.js load during server render, in +page.server.js, in onModuleInit-style server code, or in a shared module executed during server render.","commonSituations":"Calling `goto` in a load function without guarding for browser; using `invalidateAll` inside a shared store's init; importing navigation helpers into server-only code; running component code during prerender/SSR.","solutions":["Wrap the call in `if (browser)` from '$app/environment'","Move the call into onMount or an event handler that only runs client-side","For actions, use redirect/flash/state instead of calling goto during SSR","In load, use `depends`/await parent patterns instead of invalidate on the server"],"exampleFix":"// before\nimport { goto } from '$app/navigation';\nexport function load() { goto('/dashboard'); }\n// after\nimport { browser } from '$app/environment';\nimport { goto } from '$app/navigation';\nexport function load() {\n  if (browser) goto('/dashboard');\n  return redirect(302, '/dashboard'); // server-safe alternative\n}","handlingStrategy":"try-catch","validationCode":"import { browser } from '$app/environment';\n// call navigation APIs only when browser === true","typeGuard":"const canNavigate = () => typeof window !== 'undefined' && typeof document !== 'undefined';","tryCatchPattern":"import { goto } from '$app/navigation';\ntry {\n  goto('/path');\n} catch (e) {\n  if (/Cannot call `goto` on the server/.test(e.message)) {\n    // SSR context — defer to client\n  } else throw e;\n}","preventionTips":["Guard navigation calls with `if (browser)` from '$app/environment'","Prefer redirect()/error() in load functions over goto during SSR","Call navigation APIs only from event handlers, effects, or onMount","Never import navigation helpers into .server files or shared server code"],"tags":["ssr","navigation","sveltekit"],"backgroundTag":"server-only-api-misuse","analyzedSha":"03f1687fe612ce3d2d9131139b5b188d9cf90c64","analyzedAt":"2026-09-02T02:01:50.504Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}