question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

avoid using window for SSR

See original GitHub issue

When using this lib with next.js I get the following error:

 /Users/bjoern/projects/compendium2/node_modules/react-tooltip/dist/index.js:1072
[1]   if (typeof window.CustomEvent === "function") {
[1]   ^
[1] 
[1] ReferenceError: window is not defined
[1]     at dispatchGlobalEvent (/Users/bjoern/projects/compendium2/node_modules/react-tooltip/dist/index.js:1072:3)
[1]     at Function.target.rebuild (/Users/bjoern/projects/compendium2/node_modules/react-tooltip/dist/index.js:1102:5)
[1]     at Timeout._onTimeout (/Users/bjoern/projects/compendium2/frontend/.next/server/static/development/pages/compendium/[slug].js:6594:60)
[1]     at listOnTimeout (internal/timers.js:531:17)
[1]     at processTimers (internal/timers.js:475:7)
error Command failed with exit code 1.

The problem exists, because on the server side window is undefined

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
LauraBeatriscommented, Jul 18, 2020

I’m not having problems with window but instead, with the document refer to #618

1reaction
roggervalfcommented, Mar 4, 2020

Yeah, I saw before that it could be implemented as a util. I would check it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using window in React SSR: The Complete Guide
Using window in React SSR: The Complete Guide What “window is not defined” and “expected server html to contain div” really mean.
Read more >
React JS Server side issue - window not found - Stack Overflow
Your window && and if (window) checks with are failing because in JavaScript not declared and 'undefined' are different things.
Read more >
Better handling for window object in SSR environment - GitHub
Better handling for window and document object in SSR environment. This library doesn't implement the DOM (like JSDOM), it just patches (or creates...
Read more >
ssr-window - npm
Start using ssr-window in your project by running `npm i ssr-window`. There are 168 other projects in the npm registry using ssr-window.
Read more >
Window is undefined during SSR - RichHewlett.com
If when server side rendering a React application (other JS frameworks are available) that makes use of the global window object during the ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found