Pusher with encryption, window is not defined on Next.js
See original GitHub issueDo you want to request a feature or report a bug? Bug What is the current behavior?
import Pusher from "pusher-js/with-encryption";
If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem via https://jsfiddle.net or similar.
- Create a next app
- Install pusher-js@latest
- import Pusher from “pusher-js/with-encryption”;
- Will crash about window is not defined
What is the expected behavior? Should handle if the lib is being imported in SSR and just early return.
Which versions of Pusher, and which browsers / OS are affected by this issue? Did this work in previous versions of Pusher? If so, which? 7.3.0 - latest
Issue Analytics
- State:
- Created a year ago
- Comments:6
Top Results From Across the Web
"window is not defined" error when using webpack + pusher-js ...
It should be import Pusher from 'pusher-js' . Can you try that? I don't think that will get rid of the error though......
Read more >Window is not defined in Next.js React app - Stack Overflow
So we have to use back window object from the browser. if (typeof window !== "undefined") { // Client-side-only ...
Read more >pusher-js - npm
Pusher Channels JavaScript library for browsers, React Native, NodeJS and web workers. Latest version: 8.0.0, last published: 7 days ago.
Read more >How to solve "window is not defined" errors in React and Next.js
Because in the Node.js world, window is not defined, window is only available in browsers. There are three ways to solve that: 1....
Read more >Pusher Channels Docs | JavaScript Quick Start Guide
Use our JavaScript quick start guide to get set up with Channels and publish the first event to your web app.
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
I’m starting to suspect the entrypoint for /with-encryption isn’t working well with Next. Bear with us as this is being prioritised.
I have the same issue with next V12.3.1 and pusher-js V7.4.1. I solved this issue temporarily by using
require("pusher-js/with-encryption")
inside auseEffect
and assigning it to a ref. Hope this gets fixed soon. Thanks in advance.