Cannot call invalidateAll() on the server #9683
Replies: 8 comments 2 replies
-
|
I temporarily "fixed" by setting export const ssr = false but I know that this is not recommended. |
Beta Was this translation helpful? Give feedback.
-
|
You're getting this because you indeed cannot call |
Beta Was this translation helpful? Give feedback.
-
|
The invalidateAll() function is within the +page.svelte file inside the <script></script> tag.
|
Beta Was this translation helpful? Give feedback.
-
|
You should put the setInterval invocation in the onMount lifecycle function if you want it to only run on the client side. Otherwise, you can always check the browser variable |
Beta Was this translation helpful? Give feedback.
-
|
I'll try out that. Thanks. |
Beta Was this translation helpful? Give feedback.
-
|
So, without const ssr = false, I tried the suggestion but this is the result: Code: <script>
...
function actualizarDatos() {
invalidateAll();
convertToLoaded();
}
onMount(async () => {
actualizarDatos();
setInterval(() => {
if (chequearHorarioOperatoria(moment().tz("America/New_York"))) {
// console.log('estamos en horario de operatoria');
actualizarDatos();
} else {
//console.log('no estamos en horario de operatoria');
}
}, 60000);
});
</script>I started my project from the ts skeleton boilerplate. |
Beta Was this translation helpful? Give feedback.
-
|
Presumably your previous error with invalidateAll was masking another error where either you or some library you import is trying to access Once again, we can't really investigate without a minimal repro. |
Beta Was this translation helpful? Give feedback.

Uh oh!
There was an error while loading. Please reload this page.
-
Describe the bug
I started with a typescript boilerplate app from "@sveltejs/kit": "^1.5.0". I added a +page.server.ts with a load function (server-side). I want it to be rerun. I added an invalidateAll() in my +page.svelte but I always get "Cannot call invalidateAll() on the server".
Reproduction
run npm create svelte@latest my-app
pick skeleton project --> typescript notation
cd my-app
npm install
create a +page.server.ts in .src/routes
add an invalidateAll() function in +page.svelte
npm run dev -- --open
Logs
Error: Cannot call invalidateAll(...) on the server at Module.eval (/node_modules/@sveltejs/kit/src/runtime/app/navigation.js:9:9) at actualizarDatos (+page.svelte:20:2) at +page.svelte:23:1 at Object.$$render (/node_modules/svelte/internal/index.mjs:1997:22) at Object.default (root.svelte:42:40) at eval (/src/routes/+layout.svelte:20:69) at Object.$$render (/node_modules/svelte/internal/index.mjs:1997:22) at root.svelte:41:39 at $$render (/node_modules/svelte/internal/index.mjs:1997:22) at Object.render (/node_modules/svelte/internal/index.mjs:2005:26) Error: Cannot call invalidateAll(...) on the server at Module.eval (/node_modules/@sveltejs/kit/src/runtime/app/navigation.js:9:9) at actualizarDatos (+page.svelte:20:2) at +page.svelte:23:1 at Object.$$render (/node_modules/svelte/internal/index.mjs:1997:22) at Object.default (root.svelte:42:40) at eval (/src/routes/+layout.svelte:20:69) at Object.$$render (/node_modules/svelte/internal/index.mjs:1997:22) at root.svelte:41:39 at $$render (/node_modules/svelte/internal/index.mjs:1997:22) at Object.render (/node_modules/svelte/internal/index.mjs:2005:26)System Info
System: OS: Linux 5.15 Ubuntu 20.04.5 LTS (Focal Fossa) CPU: (8) x64 Intel(R) Core(TM) i5-1035G1 CPU @ 1.00GHz Memory: 5.42 GB / 15.29 GB Container: Yes Shell: 5.0.17 - /bin/bash Binaries: Node: 16.15.1 - /usr/local/bin/node Yarn: 1.22.19 - /usr/bin/yarn npm: 9.6.1 - /usr/local/bin/npm Browsers: Brave Browser: 110.1.48.171 Chrome: 110.0.5481.177 Firefox: 111.0 npmPackages: @sveltejs/adapter-auto: ^2.0.0 => 2.0.0 @sveltejs/kit: ^1.5.0 => 1.15.2 svelte: ^3.54.0 => 3.58.0 vite: ^4.2.0 => 4.2.1Severity
blocking all usage of SvelteKit
Additional Information
No response
Beta Was this translation helpful? Give feedback.
All reactions