Do you want to request a feature or report a bug?
Bug
What is the current behavior?
Code meant to only run in the browser is running on the server. The error I'm seeing is:
UnhandledPromiseRejectionWarning: TypeError: window.addEventListener is not a function
at ./node_modules/react-dom/node_modules/schedule/cjs/schedule.development.js:366:10
at Object.<anonymous> (./node_modules/react-dom/node_modules/schedule/cjs/schedule.development.js:421:5)
at Module._compile (module.js:653:30)
at Object.Module._extensions..js (module.js:664:10)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
at Function.Module._load (module.js:498:3)
at Module.require (module.js:597:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (./node_modules/react-dom/node_modules/schedule/index.js:6:20)
If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem. Your bug will get fixed much faster if we can run your code and it doesn't have dependencies other than React. Paste the link to your JSFiddle (https://jsfiddle.net/Luktwrdm/) or CodeSandbox (https://codesandbox.io/s/new) example below:
We are using import { findDOMNode } from 'react-dom' in one of our components and the server render is broken due to this dependency/file being pulled in.
What is the expected behavior?
To not error, I guess. The root problem seems to be a faulty check of environment somewhere.
Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
This has been narrowed down to just 16.5.2 -- doing nothing but downgrading to 16.5.1 using npm install --save [email protected] [email protected] fixes the issue.
This seems related to this other issue: https://github.com/facebook/react/issues/13694 which looks like it is now fixed in master.
Yeah, same issue. It means you define window on the server which ideally you shouldn't be doing. But we adjusted the heuristic to also check for window.addEventListener separately in the next version.
Thanks for pointing that out. We don't have anywhere in our codebase where we set global.window except in our tests, but maybe a dependency is doing it. I'll have to dig deeper.
Just recently updated react-dom and am having this same issue, too. @RamIdeas you have any eureka moments you're able to share? :) My project, specifically, is a react-native app via expo; not sure if that helps any.
I didn't have time to dig into which dependency is declaring window but we just pinned react and react-dom to 16.5.1
Most helpful comment
Yeah, same issue. It means you define
windowon the server which ideally you shouldn't be doing. But we adjusted the heuristic to also check forwindow.addEventListenerseparately in the next version.