-1

编辑 2:观察和问题

  1. 我和贾斯汀下面的评论者很确定问题是由于错误的build.sbt配置造成的。然而,这是我第一次看到一个错误的build.sbt配置,它实际上适用于除选择器之外的所有其他东西。也许那是因为他们使用宏,而我通常避免使用它们。

  2. 为什么是否Flow.merge使用与Flow.map问题是否与问题有关sbt

  3. 可疑的 build.sbt 提取

    lazy val server = project .dependsOn(sharedJvm, client)

  4. 可疑的堆栈跟踪

所以这是堆栈的顶部:它从我找不到的方法到链接环境到字符串编码实用程序。好的。

server java.lang.RuntimeException: stub

嗯?stub?

server  at scala.sys.package$.error(package.scala:27)
server  at scala.scalajs.runtime.package$.linkingInfo(package.scala:143)
server  at scala.scalajs.runtime.package$.environmentInfo(package.scala:137)

嗯?

server  at scala.scalajs.js.Dynamic$.global(Dynamic.scala:78)

???

server  at boopickle.StringCodec$.encodeUTF8(StringCodec.scala:56)

编辑 1:我的大而漂亮的 build.sbt 可能是问题所在

你看不到的是我在我的project文件夹中组织的:

  • JvmDependencies.scala它具有常规的 JVM 依赖项
  • SjsDependencies.scalaDef.settingsKeyslibraryDependencies上有JsModuleIDs
  • WebJarDependencies.scala其中有 javascripts 和 css 的

构建.sbt

lazy val    shared = (crossProject.crossType(CrossType.Pure) in file("shared"))
  .configure(_.enablePlugins(ScalaJSPlugin))
  .settings(SjsDependencies.pickling.toSettingsDefinition(): _*)
  .settings(SjsDependencies.tagsAndDom.toSettingsDefinition(): _*)
  .settings(SjsDependencies.css.toSettingsDefinition(): _*)

lazy val sharedJvm = shared.jvm
lazy val  sharedJs = shared.js

lazy val    cmdlne = project
  .dependsOn(sharedJvm)
  .settings(
    libraryDependencies ++= (
      JvmDependencies.commandLine ++
      JvmDependencies.logging     ++
      JvmDependencies.akka        ++
      JvmDependencies.serialization
    )
  )

lazy val    client = project
  .enablePlugins(ScalaJSPlugin, SbtWeb, SbtSass)
  .dependsOn(sharedJs)
  .settings(
    (SjsDependencies.shapeless ++ SjsDependencies.audiovideo ++ SjsDependencies.databind ++ SjsDependencies.functional ++ SjsDependencies.lensing ++ SjsDependencies.logging ++ SjsDependencies.reactive).toSettingsDefinition(),
    jsDependencies ++= WebjarDependencies.js,
    libraryDependencies ++= WebjarDependencies.notJs,
    persistLauncher in Compile := true
  )

lazy val    server = project
  .dependsOn(sharedJvm, client)
  .enablePlugins(SbtNativePackager)
  .settings(

    copyWebJarResources := { streams.value.log("Copying webjar resources")
      val `Web Modules target directory` = (resourceManaged in Compile).value / "assets"
      val `Web Modules source directory` = (WebKeys.assets in Assets in client).value / "lib"

      final class UsefulFileFilter(acceptable: String*) extends FileFilter {

        // TODO ADJUST TO EXCLUDE JS MAP FILES
        import scala.collection.JavaConversions._
        def accept(file: File) = (file.isDirectory && FileUtils.listFiles(file, acceptable.toArray, true).nonEmpty) || acceptable.contains(file.ext) && !file.name.contains(".js.")
      }

      val `file filter` = new UsefulFileFilter("css", "scss", "sass", "less", "map")

      IO.createDirectory(`Web Modules target directory`)
      IO.copyDirectory(source = `Web Modules source directory`, target = `Web Modules target directory` / "script")
      FileUtils.copyDirectory(`Web Modules source directory`, `Web Modules target directory` / "style", `file filter`)
    },

    // run the copy after compile/assets but before managed resources
    copyWebJarResources <<= copyWebJarResources dependsOn(compile in Compile, WebKeys.assets in Compile in client, fastOptJS in Compile in client),
    managedResources in Compile <<= (managedResources in Compile) dependsOn copyWebJarResources,

    watchSources <++= (watchSources in client),


    resourceGenerators in Compile <+= Def.task {
      val files = ((crossTarget in(client, Compile)).value ** ("*.js" || "*.map")).get
      val mappings: Seq[(File,String)] = files pair rebase((crossTarget in(client, Compile)).value, ((resourceManaged in  Compile).value / "assets/").getAbsolutePath )
      val map: Seq[(File, File)] = mappings.map { case (s, t) => (s, file(t))}
      IO.copy(map).toSeq
    },

    reStart <<= reStart dependsOn (managedResources in Compile),

    libraryDependencies ++= (
      JvmDependencies.akka                ++
      JvmDependencies.jarlocating         ++
      JvmDependencies.functional          ++
      JvmDependencies.serverPickling      ++
      JvmDependencies.logging             ++
      JvmDependencies.serialization       ++
      JvmDependencies.testing
    )
  )

编辑0:一个非常晦涩的聊天线程有一个人说我的感受:不,不是**** scala,但是

Mark Eibes @i-am-the-slime 2015 年 10 月 15 日 09:37 @ochrons 我还在战斗。我似乎不能再腌制任何东西了。 https://gitter.im/scala-js/scala-js/archives/2015/10/15

akka我有一个相当简单的要求 - 我在定义的 http 服务器上有一个 Web 套接字路由AkkaServerLogEventToMessageHandler()

object AkkaServerLogEventToMessageHandler
  extends Directives {

  val sourceOfLogs =

    Source.actorPublisher[AkkaServerLogMessage](AkkaServerLogEventPublisher.props) map {
      event ⇒
        BinaryMessage(
          ByteString(
            Pickle.intoBytes[AkkaServerLogMessage](event)
          )
        )
    }

  def apply(): server.Route = {
    handleWebSocketMessages(
      Flow[Message].merge(sourceOfLogs)
    )
  }

}

这以最明显的方式适合一小组路线。

现在为什么我不能得到boopickle, upickle, 或prickle序列化像这个愚蠢的案例类这样简单的东西?

sealed case class AkkaServerLogMessage(
                                 message:   String,
                                 level:     Int,
                                 timestamp: Long
                               )
  • 无嵌套
  • 所有原始类型
  • 没有泛型
  • 只有他们三个

这些都产生了大致相同的错误

  • 使用所有三个常见的pickler来编写
  • 使用TextMessage代替BinaryMessage和相应的upickleprickle writeJs或任何方法
  • case class下降变为无(无,如无成员)
  • 改变输入本身到case class
  • 导入各种排列Implicits和下划线的东西

...具体来说,他们给了我关于同一个愚蠢错误的变体(不是同一个错误,但非常相似)

server [ERROR] [04/21/2016 22:04:00.362] [app-akka.actor.default-dispatcher-7] [akka.actor.ActorSystemImpl(app)] WebSocket handler failed with stub
server java.lang.RuntimeException: stub
server  at scala.sys.package$.error(package.scala:27)
server  at scala.scalajs.runtime.package$.linkingInfo(package.scala:143)
server  at scala.scalajs.runtime.package$.environmentInfo(package.scala:137)
server  at scala.scalajs.js.Dynamic$.global(Dynamic.scala:78)
server  at boopickle.StringCodec$.encodeUTF8(StringCodec.scala:56)
server  at boopickle.Encoder.writeString(Codecs.scala:338)
server  at boopickle.BasicPicklers$StringPickler$.pickle(Pickler.scala:183)
server  at boopickle.BasicPicklers$StringPickler$.pickle(Pickler.scala:134)
server  at boopickle.PickleState.pickle(Pickler.scala:511)
server  at shindig.clientaccess.handler.AkkaServerLogEventToMessageHandler$$anonfun$1$Pickler$macro$1$2$.pickle(AkkaServerLogEventToMessageHandler.scala:35)
server  at shindig.clientaccess.handler.AkkaServerLogEventToMessageHandler$$anonfun$1$Pickler$macro$1$2$.pickle(AkkaServerLogEventToMessageHandler.scala:35)
server  at boopickle.PickleImpl$.apply(Default.scala:70)
server  at boopickle.PickleImpl$.intoBytes(Default.scala:75)
server  at shindig.clientaccess.handler.AkkaServerLogEventToMessageHandler$$anonfun$1.apply(AkkaServerLogEventToMessageHandler.scala:35)
server  at shindig.clientaccess.handler.AkkaServerLogEventToMessageHandler$$anonfun$1.apply(AkkaServerLogEventToMessageHandler.scala:31)

这有效

  • 不使用Flow.merge(达不到目的,我想继续发送日志)
  • 使用静态值
  • 其他没用的东西

上诉

请让我知道我在哪里以及为什么愚蠢...今天我以不同的形式在这个问题上花了四个小时,这让我发疯了。

4

2 回答 2

1

在您的build.sbt中,您有:

lazy val shared = (crossProject.crossType(CrossType.Pure) in file("shared"))
  .configure(_.enablePlugins(ScalaJSPlugin))

不要这样做。永远不要在跨项目上启用 Scala.js 插件。这也将它添加到 JVM 端,这将造成严重破坏。最值得注意的是,这将导致%%%解析 JVM 项目中依赖项的 Scala.js 工件,这非常糟糕。这就是导致您的问题的原因。

crossProject已经将 Scala.js 插件添加到 JS 部分,并且只有那个。所以只需删除该enablePlugins行。

于 2016-04-22T04:16:01.473 回答
0

谜团已揭开。感谢@Justin du Coeur 为我指明了正确的方向。

没有特别工作的原因boopickle是因为在依赖链中我在项目中同时包含了sjsjvm版本。boopickleserver

我删除了server dependsOnforclient和 forsharedJsboopickle从共享依赖项中删除。现在它起作用了。

于 2016-04-22T04:14:02.137 回答