Ошибка типа: буфер объектной функции (субъект, кодирование, смещение) {

#node.js #buffer

#node.js #буфер

Вопрос:

У меня возникает ошибка, когда я использую свой экспресс-сервер с буфером, он вылетает в этой строке:

 authorization = Buffer.from(authorization, 'base64').toString('utf8')
  

Сообщение об ошибке:

Ошибка типа:

  Object function Buffer(subject, encoding, offset) { if (!(this instanceof Buffer)) { return new Buffer(subject, encoding, offset); } var type; if (typeof offset === 'number') { if (!Buffer.isBuffer(subject)) { throw new TypeError('First argument must be a Buffer when slicing'); } this.length =  encoding > 0 ? Math.ceil(encoding) : 0; this.parent = subject.parent ? subject.parent : subject; this.offset = offset; } else {  switch (type = typeof subject) { case 'number': this.length =  subject > 0 ? Math.ceil(subject) : 0; break; case 'string': this.length = Buffer.byteLength(subject, encoding); break; case 'object': this.length =  subject.length > 0 ? Math.ceil(subject.length) : 0; break; default: throw new TypeError('First argument needs to be a number, '   'array or string.'); } if (this.length > Buffer.poolSize) {this.parent = new SlowBuffer(this.length); this.offset = 0; } else if (this.length > 0) { if (!pool || pool.length - pool.used < this.length) allocPool(); this.parent = pool; this.offset = pool.used;  pool.used = (pool.used   this.length   7) amp; ~7; } else {  this.parent = zeroBuffer; this.offset = 0; }  if (typeof subject !== 'number') { if (type === 'string') {  this.length = this.write(subject, 0, encoding);} else if (Buffer.isBuffer(subject)) { if (subject.parent) subject.parent.copy(this.parent, this.offset, subject.offset, this.length   subject.offset); else subject.copy(this.parent, this.offset, 0, this.length); } else if (isArrayIsh(subject)) { for (var i = 0; i < this.length; i  ) this.parent[i   this.offset] = subject[i]; } } } SlowBuffer.makeFastBuffer(this.parent, this, this.offset, this.length); } has no method 'from'
  

Ответ №1:

Ваш Buffer объект не содержит никакой from функции. Вы не используете правильный объект буфера. Я думаю, вы хотите использовать Node.js Буфер. Убедитесь, что вы действительно используете его, и у вас есть обновленная версия.