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

Version 1.5.2 breaks y-websocket in the browser #166

Closed
kevinvalk opened this issue Jan 16, 2024 · 4 comments
Closed

Version 1.5.2 breaks y-websocket in the browser #166

kevinvalk opened this issue Jan 16, 2024 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@kevinvalk
Copy link

Describe the bug
On new WebsocketProvider the following error is thrown.

y-websocket.js?v=f1f96d6f:381 Uncaught (in promise) TypeError: process.on is not a function
    at new WebsocketProvider (y-websocket.js?v=f1f96d6f:381:15)

To Reproduce

  • Use version 1.5.2
  • Simple page in the BROWSER
  • Call new WebsocketProvide

Expected behavior
No error

Screenshots
If applicable, add screenshots to help explain your problem.

Environment Information

  • Browser
  • Yjs
  ├─┬ @milkdown/[email protected]
  │ ├─┬ [email protected]
  ├─┬ [email protected]
  ├─┬ [email protected]
  ├─┬ [email protected]
  │ ├─┬ [email protected]
  └── [email protected]

Additional context
So in commit 882ac9e the logic for (if I read correctly) detecting if it is running in a browser was removed. It is weird, because the original PR #165 keeps this intact so maybe the PR merge went wrong?

882ac9e#diff-bf6cbbe721bbeff64c972b548f6291dc24bba8fd0e1cef5b91d87513c6a0b362L403-L405

@kevinvalk kevinvalk added the bug Something isn't working label Jan 16, 2024
@jblyberg
Copy link
Contributor

This is happening for me as well.

Unhandled application error: TypeError: process.on is not a function
WebsocketProvider y-websocket.js:361

Reference:

if (typeof process !== 'undefined') {
  process.on('exit', this._exitHandler)
}

@dmonad dmonad closed this as completed in 635f39d Jan 17, 2024
@dmonad
Copy link
Member

dmonad commented Jan 17, 2024

Note that this only happens because you are using a bundler (or some extension) that tries to polyfill nodejs.

I added an environment check to avoid this. Let me know if this doesn't fix the issue. If not, please supply the specific build steps that cause the issue.

@jblyberg
Copy link
Contributor

This worked for me, thanks. I am using vite 5.0.11. Incidentally, this same issue manifested at the same time in another package I'm using.

@kevinvalk
Copy link
Author

@dmonad thanks for adding environment check!

Small note, the check was not added to the destroy method and that can still throw an error in this case (when process is (partially) polyfilled).

if (typeof process !== 'undefined') {
process.off('exit', this._exitHandler)
}

Can you add the env.isNode to that place as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants