I am trying to create a facade for the npm library 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 file of the js library. It is called from the toBuffer
function.
My code using the facade should work:
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)
Also have a look at the whole project, it's very little code.
Solution: When avsc is used on the client side with webpack or browserify, one has to use require('avsc/etc/browser/avsc').