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.thesamet.scalapb" %%% "scalapb-runtime" % scalapb.compiler.Version.scalapbVersion,

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

Since the ScalaJS compiler depends on an old version of protobuf it is recommended to work with the compilerplugin-shaded artifact. This artifact contains a shaded version of protobuf-java and other dependencies. Have this in your project/scalapb.sbt file instead of what described in the standard installation instructions:

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

   libraryDependencies += "com.thesamet.scalapb" %% "compilerplugin-shaded" % "0.9.4"


Example project:

Example with multi-project build:

Live demo: