diff --git a/src/use-swr.ts b/src/use-swr.ts index 2bd493997..960f32156 100644 --- a/src/use-swr.ts +++ b/src/use-swr.ts @@ -55,7 +55,12 @@ const now = (() => { })() // setup DOM events listeners for `focus` and `reconnect` actions -if (!IS_SERVER && window.addEventListener && document.addEventListener) { +if ( + !IS_SERVER && + window.addEventListener && + typeof document !== 'undefined' && + typeof document.addEventListener !== 'undefined' +) { const revalidate = revalidators => { if (!defaultConfig.isDocumentVisible() || !defaultConfig.isOnline()) return