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.

Pusher with encryption, window is not defined on Next.js

See original GitHub issue

Do 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:open
  • Created a year ago
  • Comments:6

github_iconTop GitHub Comments

3reactions
benjamin-tang-pushercommented, Oct 26, 2022

I’m starting to suspect the entrypoint for /with-encryption isn’t working well with Next. Bear with us as this is being prioritised.

0reactions
ardalan-nhdcommented, Nov 13, 2022

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 a useEffect and assigning it to a ref. Hope this gets fixed soon. Thanks in advance.

Read more comments on GitHub >

github_iconTop 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 >

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