TypeError: this.buf.utf8Write is not a function

TypeError: this.buf.utf8Write is not a function

我正在尝试为 js 库的 npm 库 avsc. When I compile with sbt fastOptJS::webpack and open the .html file, I get TypeError: this.buf.utf8Write is not a function from the line this.buf.utf8Write(s, pos, len); in that 文件创建外观。它是从 toBuffer 函数调用的。

我使用外观的代码应该可以工作:

val schema = """{"type" : "record", "name": "Pet", "fields": [{"name": "name", "type": "string"}]}"""
val petType = avro.parse(schema)
val jsDict = js.Dictionary("name" -> "Tom")
println(petType.isValid(jsDict)) // prints 'true'
val buf = petType.toBuffer(jsDict)

也看看全文project,代码很少

解决方法:当avsc在客户端与webpack或browserify一起使用时,必须使用require('avsc/etc/browser/avsc').