Skip to content

WebSocket.send() fails when bufferutil is not installed #2288

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

Open
1 task done
mihail-8480 opened this issue Jun 11, 2025 · 1 comment
Open
1 task done

WebSocket.send() fails when bufferutil is not installed #2288

mihail-8480 opened this issue Jun 11, 2025 · 1 comment

Comments

@mihail-8480
Copy link

Is there an existing issue for this?

  • I've searched for any related issues and avoided creating a duplicate issue.

Description

I am using ws as a WebSocket client in a Next.js application in production mode inside of a docker container, and I got this error before installing bufferutil:

web-1  | TypeError: t.mask is not a function
web-1  |     at e.exports.mask (.next/server/chunks/4059.js:2:17385)
web-1  |     at y.frame (.next/server/chunks/4059.js:2:25319)
web-1  |     at y.dispatch (.next/server/chunks/4059.js:2:28129)
web-1  |     at y.send (.next/server/chunks/4059.js:2:27662)
web-1  |     at I.send (.next/server/chunks/4059.js:2:9247)
web-1  |     at I.i (.next/server/chunks/9184.js:58:4416)

This bug doesn't happen when running Next.js in development mode.

ws version

^8.18.2

Node.js Version

v23.11.1

System

  System:
    OS: Linux 6.14 Debian GNU/Linux 12 (bookworm) 12 (bookworm)
    CPU: (16) x64 Intel(R) Core(TM) i7-10700F CPU @ 2.90GHz
    Memory: 24.71 GB / 31.25 GB
    Container: Yes
    Shell: 5.2.15 - /bin/bash

Expected result

ws.send() to not throw

Actual result

ws.send() throws TypeError: t.mask is not a function

Attachments

No response

@lpinca
Copy link
Member

lpinca commented Jun 11, 2025

This is not a ws issue.

$ npm i ws

added 1 package in 272ms
$ npm ls
gh-2288@ /Users/luigi/Desktop/gh-2288
`-- [email protected]
$ cat index.mjs 
import WebSocket from 'ws';

const ws = new WebSocket('wss://websocket-echo.com/');

ws.on('error', console.error);

ws.on('open', function open() {
  console.log('connected');
  ws.send(Date.now());
});

ws.on('close', function close() {
  console.log('disconnected');
});

ws.on('message', function message(data) {
  console.log(`Round-trip time: ${Date.now() - data} ms`);

  setTimeout(function timeout() {
    ws.send(Date.now());
  }, 500);
});
$ node index.mjs 
connected
Round-trip time: 124 ms
Round-trip time: 129 ms
Round-trip time: 130 ms
Round-trip time: 130 ms
Round-trip time: 128 ms
Round-trip time: 129 ms
Round-trip time: 129 ms
^C

It is probably a bundling issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants