-
Notifications
You must be signed in to change notification settings - Fork 146
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
Websocket support for both native Node.js WebSocket and ws. #1975
Comments
Alternatively we can force it to use the ws library only on Node versions 22 and above. const isNode22 = typeof process !== 'undefined' &&
process.versions &&
process.versions.node &&
parseInt(process.versions.node.split('.')[0], 10) >= 22;
export const WebSocket = isNode22 ? ws : /*#__PURE__*/ extractGlobal('WebSocket', ws); Will give your first suggestion a try and if that doesn't work we can go with this |
I actually like your solution for now - as a patch I think it makes sense! It will atleast keep everything between Apps and Api working perfectly! |
That being said if we can find the root in the api, that would be the best :) |
rel: polkadot-js/api#6079
Node.js v21 introduced a native WebSocket, and with v22 its not behind a flag. This causes issues for node because polkadot-js currently grabs the global websocket over the 'ws' lib if it exists. This can be found below.
common/packages/x-ws/src/node.ts
Line 10 in a328ab4
common/packages/x-global/src/index.ts
Lines 50 to 58 in a328ab4
The problem here is that the native
WebSocket
, andWs
don't have the sameErrorEvent
interface which stops the api from succesfully reconnecting. There is a few options here:Fix the reconnection on the api level, and give support for both interfaces.
Only expose one WebSocket interface in common in this case
ws
.The text was updated successfully, but these errors were encountered: