2017-01-07 14 views
0

Scalaを習う昨日から、私はMongoDBインデックス(これはうまく動作します)と対話するプロジェクトを構築し、ScalaJSを使って同じことを行います。ここでScalaJSとMongoDBドライバ:存在しないクラスを参照

は私build.sbtです:

enablePlugins(ScalaJSPlugin) 

name := "demographics" 

version := "1.0" 

scalaVersion := "2.12.1" 

libraryDependencies += "org.mongodb.scala" %% "mongo-scala-driver" % "1.2.1" 

libraryDependencies += "be.doeraene" %%% "scalajs-jquery" % "0.9.1" 
libraryDependencies += "org.scala-js" %%% "scalajs-dom" % "0.9.1" 

skip in packageJSDependencies := false 
jsDependencies += 
    "org.webjars" % "jquery" % "3.1.1"/"3.1.1/jquery.js" 

と私のメインのファイル:

package demographics.webapp 

import org.mongodb.scala._ 
import scala.scalajs.js.JSApp 

object DemographicsApp extends JSApp { 
    def main(): Unit = { 
    // connect to the bdd 
    val mongoClient: MongoClient = MongoClient() 
    val database: MongoDatabase = mongoClient.getDatabase("demographics") 
    val collection: MongoCollection[Document] = database.getCollection("demographics") 
    } 
} 

非常に基本的な:ちょうどコレクションに接続します。

悲しいこと

、私はSBTシェルの「fastOptJS」を起動すると、次のエラーが表示されます。

[info] Compiling 1 Scala source to C:\...\target\scala-2.12\classes... 
[info] Fast optimizing C:\...\target\scala-2.12\untitled1-fastopt.js 
[error] Referring to non-existent class org.mongodb.scala.bson.DefaultHelper$DefaultsTo$ 
[error] called from demographics.webapp.DemographicsApp$.main()scala.Unit 
[error] called from scala.scalajs.js.JSApp.$$js$exported$meth$main()java.lang.Object 
[error] called from demographics.webapp.PrenomApp$.$$js$exported$meth$main()java.lang.Object 
[error] called from demographics.webapp.DemographicsApp$.main 
[error] exported to JavaScript with @JSExport 
[error] involving instantiated classes: 
[error] demographics.webapp.PrenomApp$ 
[error] Referring to non-existent class org.mongodb.scala.MongoClient$ 
[error] called from demographics.webapp.DemographicsApp$.main()scala.Unit 
[error] called from scala.scalajs.js.JSApp.$$js$exported$meth$main()java.lang.Object 
[error] called from demographics.webapp.PrenomApp$.$$js$exported$meth$main()java.lang.Object 
[error] called from demographics.webapp.DemographicsApp$.main 
[error] exported to JavaScript with @JSExport 
[error] involving instantiated classes: 
[error] demographics.webapp.DemographicsApp$ 
[error] Referring to non-existent class org.mongodb.scala.bson.collection.immutable.Document 
[error] called from demographics.webapp.DemographicsApp$.main()scala.Unit 
[error] called from scala.scalajs.js.JSApp.$$js$exported$meth$main()java.lang.Object 
[error] called from demographics.webapp.PrenomApp$.$$js$exported$meth$main()java.lang.Object 
[error] called from demographics.webapp.DemographicsApp$.main 
[error] exported to JavaScript with @JSExport 
[error] involving instantiated classes: 
[error] demographics.webapp.DemographicsApp$ 
[error] Referring to non-existent method org.mongodb.scala.bson.DefaultHelper$DefaultsTo$.$default()org.mongodb.scala.bson.DefaultHelper$DefaultsTo 
[error] called from demographics.webapp.DemographicsApp$.main()scala.Unit 
[error] called from scala.scalajs.js.JSApp.$$js$exported$meth$main()java.lang.Object 
[error] called from demographics.webapp.PrenomApp$.$$js$exported$meth$main()java.lang.Object 
[error] called from demographics.webapp.DemographicsApp$.main 
[error] exported to JavaScript with @JSExport 
[error] involving instantiated classes: 
[error] demographics.webapp.DemographicsApp$ 
[error] Referring to non-existent method org.mongodb.scala.MongoClient$.apply()org.mongodb.scala.MongoClient 
[error] called from demographics.webapp.DemographicsApp$.main()scala.Unit 
[error] called from scala.scalajs.js.JSApp.$$js$exported$meth$main()java.lang.Object 
[error] called from demographics.webapp.PrenomApp$.$$js$exported$meth$main()java.lang.Object 
[error] called from demographics.webapp.DemographicsApp$.main 
[error] exported to JavaScript with @JSExport 
[error] involving instantiated classes: 
[error] demographics.webapp.DemographicsApp$ 
[trace] Stack trace suppressed: run last compile:fastOptJS for the full output. 
[error] (compile:fastOptJS) There were linking errors 

(メインファイルに適応して)同じコードがなぜ、バニラScalaのプロジェクトに取り組んでいますこのエラーは表示されますか?

答えて

1

JVM専用ライブラリを使用しているために表示されます。 Scala.jsのmongo-scala-driverは公開されていません。それは%%%依存関係を使用して、Scala.jsで動作するScala.jsバージョンのライブラリに依存することができました。しかし、Scala.jsプロジェクトではJVM専用ライブラリを使用することはできません。

(逆に、Scala/JVMプロジェクトではScala/jVM専用ライブラリを使用できません。たとえば、scalajs-dom

関連する問題