polkadot-js / api

Promise and RxJS APIs around Polkadot and Substrate based chains via RPC calls. It is dynamically generated based on what the Substrate runtime provides in terms of metadata.
Apache License 2.0
1.07k stars 354 forks source link

error on node v22.1.0 #5880

Closed xlc closed 4 months ago

xlc commented 6 months ago
node:internal/event_target:1095
  process.nextTick(() => { throw err; });
                           ^

TypeError: Cannot read properties of null (reading 'length')
    at WebSocket.__internal__onSocketMessage (file:///Users/xiliangchen/projects/acala/chopsticks/node_modules/@polkadot/rpc-provider/ws/index.js:392:40)
    at [nodejs.internal.kHybridDispatch] (node:internal/event_target:821:20)
    at WebSocket.dispatchEvent (node:internal/event_target:756:26)
    at fireEvent (node:internal/deps/undici/undici:10966:14)
    at websocketMessageReceived (node:internal/deps/undici/undici:10988:7)
    at ByteParser.run (node:internal/deps/undici/undici:11439:17)
    at ByteParser._write (node:internal/deps/undici/undici:11315:14)
    at writeOrBuffer (node:internal/streams/writable:564:12)
    at _write (node:internal/streams/writable:493:10)
    at Writable.write (node:internal/streams/writable:502:10)

Node.js v22.1.0

failed on this line

https://github.com/polkadot-js/api/blob/baaa27ba9e5d81eefe08914973bc58a65fe648f6/packages/rpc-provider/src/ws/index.ts#L482

the message is

MessageEvent {
  type: 'message',
  defaultPrevented: false,
  cancelable: false,
  timeStamp: 1240.624208
}

and message.data is null for some reason

to reproduce, run chopsticks on nodejs v22.1.0 Original issue https://github.com/AcalaNetwork/chopsticks/issues/753

TarikGul commented 6 months ago

Not surprised node v22 is giving some issues, but also happy to start working on giving it support.

TarikGul commented 6 months ago

This will most likely not be a fast fix, but I will do my best to get it resolved soon!

TarikGul commented 4 months ago

This issue has been fixed with Nodejs 22.3.0 - The only PR i could trace this too was: https://github.com/nodejs/node/pull/52370/files

I went through a lot of rabbit holes to see what I could do to improve this locally, to not much avail. I would just recommend using 22.3.0 or above - as the lower versions had intrinsic issues with the Global WebSocket.

closing for now.

polkadot-js-bot commented 3 months ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue if you think you have a related problem or query.