Skip to content
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

[@hono/node-ws] ReferenceError: CloseEvent is not defined #595

Closed
Lorenzo0111 opened this issue Jun 27, 2024 · 2 comments · Fixed by #648
Closed

[@hono/node-ws] ReferenceError: CloseEvent is not defined #595

Lorenzo0111 opened this issue Jun 27, 2024 · 2 comments · Fixed by #648

Comments

@Lorenzo0111
Copy link

I'm using Node v20.14.0 with @hono/node-ws v1.0.1 and when listening to the onClose event it throws the following error:

events.onClose?.(new CloseEvent("close"), ctx);
                     ^

ReferenceError: CloseEvent is not defined
@MrBazlow
Copy link

MrBazlow commented Jun 28, 2024

Spotted this as well with node.js v22.3.0 although this seems to be an upstream issue which already has a committed fix. nodejs/node#53355

My monkeypatch for it right now is to just slot this in somewhere using this for reference

globalThis.CloseEvent = class CloseEvent extends Event {
  constructor(type, eventInitDict = {}) {
    super(type, eventInitDict);

    if (eventInitDict.wasClean) this.wasClean = eventInitDict.wasClean;
    if (eventInitDict.code) this.code = eventInitDict.code;
    if (eventInitDict.reason) this.reason = eventInitDict.reason;
  }

  wasClean = false;
  code = 0;
  reason = "";
};

@Lorenzo0111
Copy link
Author

Lorenzo0111 commented Jun 28, 2024

Well, close doesn't really work and connections gets multiplied everytime. I guess the module is bugged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants