Sapper: Window is not define 500 error

Created on 30 Jun 2019  路  1Comment  路  Source: sveltejs/sapper

on a window.setInterval function set on my index.svelte I get "Window is not defined 500 error but the application continues loading successfully

Most helpful comment

Just in case this is found by anybody in future - the reason for this is that setInterval which is only available in the browser, was running on the server (node) (it needs to be part of onMount to isolate it to the browser only.

The reason the application continued loading is that the call to setInterval would break SSR, and therefore cause the server rendering to fail, but the client JS would continue to load in the browser (since window is defined there), masking the server-side failure.

>All comments

Just in case this is found by anybody in future - the reason for this is that setInterval which is only available in the browser, was running on the server (node) (it needs to be part of onMount to isolate it to the browser only.

The reason the application continued loading is that the call to setInterval would break SSR, and therefore cause the server rendering to fail, but the client JS would continue to load in the browser (since window is defined there), masking the server-side failure.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nikku picture nikku  路  4Comments

nolanlawson picture nolanlawson  路  4Comments

mylastore picture mylastore  路  3Comments

UnwrittenFun picture UnwrittenFun  路  4Comments

Rich-Harris picture Rich-Harris  路  3Comments