"window is not defined" error when using webpack + pusher-js + react
See original GitHub issueIssue #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:
- Created 7 years ago
- Comments:6 (4 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
this worked for me: componentDidMount(){ var Pusher = require(‘pusher-js’); var pusher = new Pusher(‘45vb7342ca27wqwyb9df609’); }
*45vb7342ca27wqwyb9df609 - made up APP_KEY
@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.