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.

schedule/cjs/schedule.<env>.js thinks it is in the browser when run on the server

See original GitHub issue

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 react@16.5.1 react-dom@16.5.1 fixes the issue.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
gaearoncommented, Sep 26, 2018

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.

1reaction
hamlimcommented, Sep 26, 2018

This seems related to this other issue: https://github.com/facebook/react/issues/13694 which looks like it is now fixed in master.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Environment detection: node.js or browser - Stack Overflow
After which detecting the environment based on the existence of window variable would systematically fail by any module running under that scope.
Read more >
Cypress.env
Cypress runs each spec file in isolation: the browser is exited between specs. Environment variables added or changed in one spec won't be...
Read more >
Run Express server in your browser - Gleb Bahmutov
I was thinking how to call the server running in the browser. Typically, it would be called "universal" JavaScript, but I think this...
Read more >
3.4 Hiding API Keys with Environment Variables (dotenv) and ...
In this lesson, we will address how to can hide an API key using environment variables and open source the code on GitHub....
Read more >
Environment Variables in Next.js - Frontend Digest
You'll notice that the browser will log undefined . This happens since the environment variable is only defined on our server so far....
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