[GH-ISSUE #4853] SlowBuffer issue for new node versions 25.x #3060

Closed
opened 2026-02-22 18:32:27 -05:00 by yindo · 1 comment
Owner

Originally created by @tron4x on GitHub (Jan 10, 2026).
Original GitHub issue: https://github.com/Mintplex-Labs/anything-llm/issues/4853

I had a problem with slow buffers in Node.js version 25.x.
The problem occurred when calling "yarn run dev:all".
Node.js 18.x is hardcoded in the code.
I fixed it by writing a patch for it without changing the original code.

Here is the patch for server:

diff --git a/node_modules/buffer-equal-constant-time/index.js b/node_modules/buffer-equal-constant-time/index.js
index 5462c1f..f6237f9 100644
--- a/node_modules/buffer-equal-constant-time/index.js
+++ b/node_modules/buffer-equal-constant-time/index.js
@@ -1,7 +1,9 @@
 /*jshint node:true */
 'use strict';
-var Buffer = require('buffer').Buffer; // browserify
-var SlowBuffer = require('buffer').SlowBuffer;
+var BufferModule = require('buffer');
+var Buffer = BufferModule.Buffer; // browserify
+var SlowBuffer = BufferModule.SlowBuffer;
+var hasSlowBuffer = !!(SlowBuffer && SlowBuffer.prototype);
 
 module.exports = bufferEq;
 
@@ -28,14 +30,19 @@ function bufferEq(a, b) {
 }
 
 bufferEq.install = function() {
-  Buffer.prototype.equal = SlowBuffer.prototype.equal = function equal(that) {
+  Buffer.prototype.equal = function equal(that) {
     return bufferEq(this, that);
   };
+  if (hasSlowBuffer) {
+    SlowBuffer.prototype.equal = Buffer.prototype.equal;
+  }
 };
 
 var origBufEqual = Buffer.prototype.equal;
-var origSlowBufEqual = SlowBuffer.prototype.equal;
+var origSlowBufEqual = hasSlowBuffer ? SlowBuffer.prototype.equal : undefined;
 bufferEq.restore = function() {
   Buffer.prototype.equal = origBufEqual;
-  SlowBuffer.prototype.equal = origSlowBufEqual;
+  if (hasSlowBuffer) {
+    SlowBuffer.prototype.equal = origSlowBufEqual;
+  }
 };

The patch is executed with "cd server && yarn install".

copy code into file like: buffer-equal-constant-time+1.0.1.patch
put it on folder: server --> patches

Hope it helps.

Greetings
tron4x

Originally created by @tron4x on GitHub (Jan 10, 2026). Original GitHub issue: https://github.com/Mintplex-Labs/anything-llm/issues/4853 I had a problem with slow buffers in Node.js version 25.x. The problem occurred when calling "yarn run dev:all". Node.js 18.x is hardcoded in the code. I fixed it by writing a patch for it without changing the original code. Here is the patch for server: ``` diff --git a/node_modules/buffer-equal-constant-time/index.js b/node_modules/buffer-equal-constant-time/index.js index 5462c1f..f6237f9 100644 --- a/node_modules/buffer-equal-constant-time/index.js +++ b/node_modules/buffer-equal-constant-time/index.js @@ -1,7 +1,9 @@ /*jshint node:true */ 'use strict'; -var Buffer = require('buffer').Buffer; // browserify -var SlowBuffer = require('buffer').SlowBuffer; +var BufferModule = require('buffer'); +var Buffer = BufferModule.Buffer; // browserify +var SlowBuffer = BufferModule.SlowBuffer; +var hasSlowBuffer = !!(SlowBuffer && SlowBuffer.prototype); module.exports = bufferEq; @@ -28,14 +30,19 @@ function bufferEq(a, b) { } bufferEq.install = function() { - Buffer.prototype.equal = SlowBuffer.prototype.equal = function equal(that) { + Buffer.prototype.equal = function equal(that) { return bufferEq(this, that); }; + if (hasSlowBuffer) { + SlowBuffer.prototype.equal = Buffer.prototype.equal; + } }; var origBufEqual = Buffer.prototype.equal; -var origSlowBufEqual = SlowBuffer.prototype.equal; +var origSlowBufEqual = hasSlowBuffer ? SlowBuffer.prototype.equal : undefined; bufferEq.restore = function() { Buffer.prototype.equal = origBufEqual; - SlowBuffer.prototype.equal = origSlowBufEqual; + if (hasSlowBuffer) { + SlowBuffer.prototype.equal = origSlowBufEqual; + } }; ``` The patch is executed with "cd server && yarn install". copy code into file like: buffer-equal-constant-time+1.0.1.patch put it on folder: server --> patches Hope it helps. Greetings tron4x
yindo closed this issue 2026-02-22 18:32:27 -05:00
Author
Owner

@timothycarambat commented on GitHub (Jan 12, 2026):

We do right now specify Node >=18, which can have impacts between major versions if you wish to migrate to 20+. Our current target is just 18, though - so anything outside of that can be a risk for weird behaviors. That being said, we do plan to migrate to LTS very soon to keep up with all the benefits of NodeJS releases 👍

@timothycarambat commented on GitHub (Jan 12, 2026): We do right now specify Node >=18, which can have impacts between major versions if you wish to migrate to 20+. Our current target is just 18, though - so anything outside of that can be a risk for weird behaviors. That being said, we do plan to migrate to LTS very soon to keep up with all the benefits of NodeJS releases 👍
yindo changed title from SlowBuffer issue for new node versions 25.x to [GH-ISSUE #4853] SlowBuffer issue for new node versions 25.x 2026-06-05 14:50:04 -04:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Mintplex-Labs/anything-llm#3060