2017-01-07 7 views
0

어제부터 Scala를 배우면서 MongoDB 인덱스 (작동)와 상호 작용하는 프로젝트를 만들고 다른 프로젝트에서 ScalaJS를 사용하여 동일한 작업을 수행했습니다.ScalaJS 및 MongoDB 드라이버 : 존재하지 않는 클래스 참조

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") 
    } 
} 

아주 기본이 : 그냥 컬렉션에 연결

여기 내 build.sbt입니다. 나는 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 

(주 파일의 적응과) 동일한 코드를 바닐라 스칼라 프로젝트, 왜에 노력하고 있습니다 이 오류가 나타 납니까?

답변

1

JVM 전용 라이브러리를 사용하기 때문에 나타납니다. Scala.js에 mongo-scala-driver이 게시되지 않았습니다. 그것은 %%% 의존성을 사용하여 Scala.js에서 작동 할 해당 라이브러리의 Scala.js 버전에 의존 할 수있었습니다. 그러나 Scala.js 프로젝트에서는 JVM 전용 라이브러리를 사용할 수 없습니다.

(반대로, 예를 들어, 스칼라/JVM 프로젝트에 scalajs-dom을 Scala.js 전용 라이브러리를 사용할 수 없습니다.)