Getting TypeError: this is not a typed array using Buffer.from in mocha

前端 未结 3 980
心在旅途
心在旅途 2020-12-17 09:04

I\'m using Mocha / Chai to unit test a library that has recently started using nodejs\' Buffer objects to solve a different problem.

I get this error message in the

相关标签:
3条回答
  • 2020-12-17 09:38

    There are times when its difficult to update the node version especially if you are using at production so the another solution is

    use "kafka-node": "1.6.2" or lesser

    0 讨论(0)
  • 2020-12-17 09:40

    I also got the same error. You can try this

    var b = new Buffer('some string or other');
    

    Second param is encoding (optional). By default encoding will be utf-8

    0 讨论(0)
  • 2020-12-17 09:58

    You might be using an old version of Node.js.

    Buffer.from was introduced in version 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.

    There's no reference to this method in previous versions of documentiation.

    You could either update to 6.0.0 or use a deprecated constructor API, which has the following signature:

    new Buffer(str[, encoding])
    
    0 讨论(0)
提交回复
热议问题