redeagle47 redeagle47 - 2 months ago 10
Scala Question

ScalaJS IntelliJ won't recognize my library

I'm trying to use the Scalatags library, but IntelliJ won't acknowledge certain parts of the library. I have it in my build.sbt like so:

libraryDependencies += "com.lihaoyi" %% "scalatags" % "0.6.0"


In my source file, I'm importing the library like so:

import scalatags.JsDom.all._


which is exactly how it's shown in the docs here: http://www.lihaoyi.com/scalatags/#ScalaTags

But IntelliJ won't acknowledge JsDom as part of the scalatags library. If I use

import scalatags.Text.all._


there's no problem. But JsDom isn't recognized, and doesn't come up as a suggestion while typing.

What am I doing wrong?

Answer

%% uses the JVM version of the library. You need to use the platform-dependent version with %%%, like this:

libraryDependencies += "com.lihaoyi" %%% "scalatags" % "0.6.0"

This will select the JS version of the library if your project is a Scala.js project, thereby providing JS-specific parts of the API, such as scalatags.JsDom.