View on GitHub


Protocol Buffer Compiler for Scala

ScalaPB in Scala.js

Scala.js compiles Scala source code to equivalent Javascript code. It is possible to use ScalaPB generated case classes and lenses in ScalaJS, and even serialize and parse byte arrays.


  • The Java protocol buffers are unavailable, and therefore Java conversions and Java descriptors do not work (though Scala descriptors in ScalaPB >= 0.6.0 would cover most use cases)

Getting Started

Add to your library dependencies:

libraryDependencies ++= Seq(
  "com.trueaccord.scalapb" %%% "scalapb-runtime" % com.trueaccord.scalapb.compiler.Version.scalapbVersion,

  // The following needed only if you include scalapb/scalapb.proto:
  "com.trueaccord.scalapb" %%% "scalapb-runtime" % com.trueaccord.scalapb.compiler.Version.scalapbVersion % "protobuf"

Since the ScalaJS compiler depends on an old version of protobuf it is recommended to work with a shaded version of ScalaPBā€™s compiler plugin. Have this in your project/scalapb.sbt file instead of what described in the standard installation instructions:

addSbtPlugin("com.thesamet" % "sbt-protoc" % "0.99.6" exclude ("com.trueaccord.scalapb", "protoc-bridge_2.10"))

libraryDependencies += "com.trueaccord.scalapb" %% "compilerplugin-shaded" % "0.6.0-pre3"


Example project:

Example with multi-project build:

Live demo: