rsocket-js icon indicating copy to clipboard operation
rsocket-js copied to clipboard

Explicit reference to Buffer class (node)

Open GaelBi opened this issue 2 years ago • 4 comments

Hello,

Working with Angular 16, I met the following error :

ReferenceError: Buffer is not defined
    at serializeSetupFrame (Codecs.js:315:11)
    at serializeFrame (Codecs.js:227:20)
    at WebsocketDuplexConnection.send (WebsocketDuplexConnection.js:86:55)
    at ClientServerInputMultiplexerDemultiplexer.send (ClientServerMultiplexerDemultiplexer.js:144:23)
    at RSocketConnector.<anonymous> (RSocketConnector.js:146:80)

I had to expose in the global scope manually the reference to the Buffer class. But, like it is mentioned in the suggestion from the official documentation, maybe, it would be preferable to set an explicit reference of this class when it is used ?

The official documentation : https://nodejs.org/api/buffer.html#buffer "While the Buffer class is available within the global scope, it is still recommended to explicitly reference it via an import or require statement."

Desired solution

Explicit import of Buffer when it is required (like in Codecs.ts). import { Buffer } from 'node:buffer';

GaelBi avatar Aug 30 '23 15:08 GaelBi