Getting TypeError: this is not a typed array using Buffer.from in mocha
Getting TypeError: this is not a typed array using Buffer.from in mocha
我正在使用 Mocha/Chai 对最近开始使用 nodejs 的 Buffer 对象来解决不同问题的库进行单元测试。
我在单元测试中收到此错误消息:
TypeError: this is not a typed array.
at Function.from (native)
at Object.hashesMatch (index.js:29:18
at Context.<anonymous> (test/test.js:25:22)
index.js 的第 29 行是我使用 nodejs 缓冲区的地方...
var b = Buffer.from ('some string or other');
我找不到 polyfill 或解决方法,因此非常感谢您的建议。
谢谢
我也遇到了同样的错误。你可以试试这个
var b = new Buffer('some string or other');
第二个参数是编码(可选)。默认编码为 utf-8
您可能使用的是旧版本 Node.js。
Buffer.from
was introduced 版本 6.0.0:
To make the creation of Buffer objects more reliable and less error prone, the various forms of the new Buffer() constructor have been deprecated and replaced by separate Buffer.from(), Buffer.alloc(), and Buffer.allocUnsafe() methods.
previous versions 文档中未提及此方法。
您可以更新到 6.0.0 或使用已弃用的构造函数 API,它具有以下签名:
new Buffer(str[, encoding])
有时很难更新节点版本,尤其是在生产环境中使用时,因此另一种解决方案是
使用 "kafka-node": "1.6.2" 或更低
我正在使用 Mocha/Chai 对最近开始使用 nodejs 的 Buffer 对象来解决不同问题的库进行单元测试。
我在单元测试中收到此错误消息:
TypeError: this is not a typed array.
at Function.from (native)
at Object.hashesMatch (index.js:29:18
at Context.<anonymous> (test/test.js:25:22)
index.js 的第 29 行是我使用 nodejs 缓冲区的地方...
var b = Buffer.from ('some string or other');
我找不到 polyfill 或解决方法,因此非常感谢您的建议。
谢谢
我也遇到了同样的错误。你可以试试这个
var b = new Buffer('some string or other');
第二个参数是编码(可选)。默认编码为 utf-8
您可能使用的是旧版本 Node.js。
Buffer.from
was introduced 版本 6.0.0:
To make the creation of Buffer objects more reliable and less error prone, the various forms of the new Buffer() constructor have been deprecated and replaced by separate Buffer.from(), Buffer.alloc(), and Buffer.allocUnsafe() methods.
previous versions 文档中未提及此方法。
您可以更新到 6.0.0 或使用已弃用的构造函数 API,它具有以下签名:
new Buffer(str[, encoding])
有时很难更新节点版本,尤其是在生产环境中使用时,因此另一种解决方案是
使用 "kafka-node": "1.6.2" 或更低