-
Notifications
You must be signed in to change notification settings - Fork 374
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pusher with encryption, window is not defined on Next.js #624
Comments
Hi, do you also get this issue with the default Next.js static site generation? |
Not sure, probably yes. We’re just using traditional SSR, meanwhile I’m lazy loading the lib inside a Suspense boundary with SSR:false |
I can reproduce, will escalate. |
Same issue. |
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 |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you'd like this issue to stay open please leave a comment indicating how this issue is affecting you. Thank you. |
Not staled guys |
I have the same issue. It's definitely something related to |
Having same issue here with version Happens when we subscribe to the |
I have same issue with I don't want to be that guy, but I am totally going to be that guy... I just started using Pusher today because another developer had recommended it. I am currently setting everything up for a proof of concept, with the thought that if all goes well, our company will likely purchase the Pro plan. However, the lack of good documentation and the fact that an issue this simple has sat open for over a year gives me a lot of hesitation to move forward. Maybe I'm missing something, but this fix should be as simple as a typeof check with an early return? If this was just some random open source library, I would never complain. But this is an SDK for a paid enterprise product and there are only 13 open issues so you would think staying on top of something like this wouldn't be so hard. |
plus one, with nextjs pusher-js/with-encryption cannot be used without require due to window is not defined error. |
I suspect this is happening because pusher-js/webpack/config.web.js Line 25 in ed900f8
This is not the correct module format for projects using |
Made my own CJS build just now, which gets you past the initial First one: Lines 45 to 49 in ed900f8
Second one is here: pusher-js/src/runtimes/web/net_info.ts Line 15 in ed900f8
And it triggers because of this pusher-js/src/runtimes/web/net_info.ts Line 50 in ed900f8
The correct solution here is to avoid performing side effects in global scope. Instead, Pusher should ship functions that we can call when & where appropriate in our apps to do the necessary setup work. A quick fix is to guard these two code execution paths by checking |
PR is up with a fix that works in my NextJS 12.x app. Also worth noting for anyone in this thread: if you wrote |
Any update on this matter? I'm using NextJS version |
same issue with sveltekit when trying to host on cloudflare pages, i tried browser build, worker etc. nothing seems to work keep on getting this error
|
I haven't seen any activity on #819, which is discouraging, but in the meantime you might try dynamically importing at runtime: (async () => {
try {
const Pusher = (await import('pusher-js/with-encryption')).default;
const myPusherInstance = new Pusher(...);
myPusherInstance.connection.bind('connected', myConnectedCallback);
myPusherInstance.connection.bind('disconnected', myDisconnectedCallback);
myPusherInstance.signin();
} catch (error) {
...
}
})(); React apps: do this in |
not needed to use onmount as with pusher-js/worker import, it works as that build don't use window instance. |
Do you want to request a feature or report a bug?
Bug
What is the current behavior?
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.
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
The text was updated successfully, but these errors were encountered: