user438454534
user438454534

Reputation: 3689

How to exclude javascript dependencies using the sbt-scalajs plugin in a scalajs-react project?

How to exclude scalajs dependencies using sbt-scalajs plugin ?

I'm trying to import the following library

"org.webjars.bower" % "react-bootstrap-datetimepicker" % "0.0.14" / "react-bootstrap-datetimepicker.js"

But this library is downloading other dependencies ("react" and "react-bootstrap") which are already in my project and I'm getting version clashes.

I've tried using the exclude function

"org.webjars.bower" % "react-bootstrap-datetimepicker" % "0.0.14" exclude ("org.webjars.bower", "react") 

but this does not allow me to append / "react-bootstrap-datetimepicker.js" to the command.

The exception I get is:

org.scalajs.core.tools.classpath.JSLibResolveException: Some references to JS libraries could not be resolved:
- Ambiguous reference to a JS library: react-bootstrap.js
  Possible paths found on the classpath:
  - META-INF/resources/webjars/react-bootstrap/0.16.1/react-bootstrap.js
  - META-INF/resources/webjars/react-bootstrap/0.23.7/react-bootstrap.js
  originating from: adminJS:compile

    at org.scalajs.core.tools.classpath.PartialClasspath.resolveAllResourceNames(PartialClasspath.scala:137)
    at org.scalajs.core.tools.classpath.PartialClasspath.resolveDependencies(PartialClasspath.scala:80)
    at org.scalajs.core.tools.classpath.PartialClasspath.resolve(PartialClasspath.scala:64)
    at org.scalajs.sbtplugin.ScalaJSPluginInternal$$anonfun$11.apply(ScalaJSPluginInternal.scala:140)
    at org.scalajs.sbtplugin.ScalaJSPluginInternal$$anonfun$11.apply(ScalaJSPluginInternal.scala:137)
    at scala.Function1$$anonfun$compose$1.apply(Function1.scala:47)
    at sbt.$tilde$greater$$anonfun$$u2219$1.apply(TypeFunctions.scala:40)
    at sbt.std.Transform$$anon$4.work(System.scala:63)
    at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:226)
    at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:226)
    at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:17)
    at sbt.Execute.work(Execute.scala:235)
    at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:226)
    at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:226)
    at sbt.ConcurrentRestrictions$$anon$4$$anonfun$1.apply(ConcurrentRestrictions.scala:159)
    at sbt.CompletionService$$anon$2.call(CompletionService.scala:28)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

Upvotes: 4

Views: 622

Answers (1)

sjrd
sjrd

Reputation: 22085

exclude is a feature of sbt's libraryDependencies, and is not replicated in jsDependencies. So you can't declare an exclude directly in you jsDependencies. However, since jsDependencies builds on top of libraryDependencies, you can achieve what you want by combining both, with a little bit of duplicate code:

libraryDependencies +=
  "org.webjars.bower" % "react-bootstrap-datetimepicker" % "0.0.14" exclude ("org.webjars.bower", "react")
jsDependencies +=
  "org.webjars.bower" % "react-bootstrap-datetimepicker" % "0.0.14" / "react-bootstrap-datetimepicker.js"

Upvotes: 5

Related Questions