Connecting to a websocket server from a webpack bundled code via the WebsocketProvider

Hi all,

I’ve been using webpack to bundle the modules and run my code from PowerShell instead of a browser. This seems to work with the Y module, but websocket apparently doesn’t work that way.

I have installed the y-websocket module and ran it with npx y-websocket-server; and now I’d like to connect to it via the WebsocketProvider. (Essentially the example provided here: Any tips as of how to make this work with webpack? Any other workaround perhaps?


Hi @idavid,

So you’d like to create websockets connections from command line to a y-websocket server. I don’t think that PowerShell ships with JavaScript support? You probably want to run the client script (connection to the y-websocket server) using nodejs.

WebSockets is a protocol that is only natively implemented by web browsers. However, you can polyfill websocket support using the ws package.

new WebsocketProvider(url, roomname, doc, { WebSocketPolyfill: require('ws') })

WebSocketPolyfill can be any polyfill that implements the Websocket API.

I hope this is the answer you were looking for.