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.

"window is not defined" error when using webpack + pusher-js + react

See original GitHub issue

Issue #48 also describes this problem further down in the comments.

What

 29% 47/143 build modules15:33:26 web.1  | /Users/rtuser/Sites/rt/rtx/app/node_modules/pusher-js/dist/web/pusher.js:1581
15:33:26 web.1  |           if (window.addEventListener !== undefined) {
15:33:26 web.1  |               ^
15:33:26 web.1  |
15:33:26 web.1  | ReferenceError: window is not defined
15:33:26 web.1  |     at new NetInfo (/Users/rtuser/Sites/rt/rtx/app/node_modules/pusher-js/dist/web/pusher.js:1581:14)
15:33:26 web.1  |     at Object.wsStrategy (/Users/rtuser/Sites/rt/rtx/app/node_modules/pusher-js/dist/web/pusher.js:1601:20)
15:33:26 web.1  |     at __webpack_require__ (/Users/rtuser/Sites/rt/rtx/app/node_modules/pusher-js/dist/web/pusher.js:38:30)
15:33:26 web.1  |     at Object.<anonymous> (/Users/rtuser/Sites/rt/rtx/app/node_modules/pusher-js/dist/web/pusher.js:262:19)
15:33:26 web.1  |     at __webpack_require__ (/Users/rtuser/Sites/rt/rtx/app/node_modules/pusher-js/dist/web/pusher.js:38:30)
15:33:26 web.1  |     at Object.<anonymous> (/Users/rtuser/Sites/rt/rtx/app/node_modules/pusher-js/dist/web/pusher.js:75:18)
15:33:26 web.1  |     at __webpack_require__ (/Users/rtuser/Sites/rt/rtx/app/node_modules/pusher-js/dist/web/pusher.js:38:30)
15:33:26 web.1  |     at Object.<anonymous> (/Users/rtuser/Sites/rt/rtx/app/node_modules/pusher-js/dist/web/pusher.js:66:17)
15:33:26 web.1  |     at __webpack_require__ (/Users/rtuser/Sites/rt/rtx/app/node_modules/pusher-js/dist/web/pusher.js:38:30)
15:33:26 web.1  |     at /Users/rtuser/Sites/rt/rtx/app/node_modules/pusher-js/dist/web/pusher.js:58:18
15:33:26 web.1  | exited with code 1```

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
kim-kolosekcommented, Oct 25, 2016

this worked for me: componentDidMount(){ var Pusher = require(‘pusher-js’); var pusher = new Pusher(‘45vb7342ca27wqwyb9df609’); }

*45vb7342ca27wqwyb9df609 - made up APP_KEY

1reaction
hphcommented, Sep 6, 2016

@hderms Have you resolved your problem? If not, try moving the Pusher part of your application into the componentDidMount function of your component, it should be enough.

Read more comments on GitHub >

github_iconTop Results From Across the Web

"window is not defined" error when using webpack + pusher-js + react
"window is not defined" error when using webpack + pusher-js + react.
Read more >
'window is not defined' error when using style-loader with ...
After looking through Stack and the Github issues for style-loader I am not finding any solution. Here is my webpack file: const path...
Read more >
How to solve "window is not defined" errors in React and Next.js
Next.js is a React framework with pre-rendering abilities. ... Then it will fail with "ReferenceError: window is not defined": React error.
Read more >
Window is not defined after a build with Webpack-Reactjs
I also had the ReferenceError: window is not defined. issue with Webpack 4, and found that adding globalObject: 'this' line to the output...
Read more >
Echo build failing due to Pusher.js requiring React Native
ERROR Failed to compile with 1 errors This dependency was not found: ... pusher-js/dist/react-native/pusher.js To install it, you can run: npm install ...
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