5

I have a ScalaJS project and running the sbt command fastOptJS::startWebpackDevServer in Windows 10 yields errors like in the following snippet:

[error] (Emitted value instead of an instance of Error) Cannot find source file 'https://raw.githubusercontent.com/japgolly/scalacss/v0.5.3/js/src/main/scala/scalacss/defaults/PlatformExports.scala': Error: Can't resolve './https://raw.githubusercontent.com/japgolly/scalacss/v0.5.3/js/src/main/scala/scalacss/defaults/PlatformExports.scala' in '/project/root/target/scala-2.12/scalajs-bundler/main'
[error]  @ multi (webpack)-dev-server/client?http://localhost:8080 ./mockup-fastopt.js
[error] WARNING in ./mockup-fastopt.js
[error] (Emitted value instead of an instance of Error) Cannot find source file 'https://raw.githubusercontent.com/japgolly/scalacss/v0.5.3/js/src/main/scala/scalacss/internal/Platform.scala': Error: Can't resolve './https://raw.githubusercontent.com/japgolly/scalacss/v0.5.3/js/src/main/scala/scalacss/internal/Platform.scala' in '/project/root/target/scala-2.12/scalajs-bundler/main'
[error]  @ multi (webpack)-dev-server/client?http://localhost:8080 ./mockup-fastopt.js
[error] WARNING in ./mockup-fastopt.js
[error] (Emitted value instead of an instance of Error) Cannot find source file 'https://raw.githubusercontent.com/japgolly/scalacss/v0.5.3/js/src/main/scala/scalacss/internal/mutable/Mutex.scala': Error: Can't resolve './https://raw.githubusercontent.com/japgolly/scalacss/v0.5.3/js/src/main/scala/scalacss/internal/mutable/Mutex.scala' in '/project/root/target/scala-2.12/scalajs-bundler/main'
[error]  @ multi (webpack)-dev-server/client?http://localhost:8080 ./mockup-fastopt.js

It's pretty weird because it tries to resolve a URL from the current directory as indicated in this part: Error: Can't resolve './https://raw.githubusercontent.com/scala/scala/v2.12.4/src/library/scala/util/control/Breaks.scala'

I've also tried running fastOptJS::webpack and instead of errors it yields warnings.

Here's my build.sbt file:

import sbt.Keys._

lazy val root: Project = (project in file("."))
  .settings(
    name := Settings.name,
    version := Settings.version,
    scalaVersion := Settings.versions.scala,
    libraryDependencies ++= Settings.scalaJsDependencies.value,
    skip in packageJSDependencies := false,
    npmDependencies in Compile ++= Settings.npmDependencies.value,
    scalaJSUseMainModuleInitializer := true,
    scalaJSUseMainModuleInitializer.in(Test) := false,
    webpackBundlingMode := BundlingMode.Application
  )
  .enablePlugins(ScalaJSPlugin, WorkbenchPlugin, ScalaJSBundlerPlugin)

and the Settings.scala file:

import sbt._
import org.scalajs.sbtplugin.ScalaJSPlugin.autoImport._

object Settings {

  val name = """mockup"""
  val version = "0.0.0"

  object versions {
    val materialUi = "0.19.4"
    val react = "16.1.1"
    val scala = "2.12.4"
    val scalaCSS = "0.5.3"
    val scalaJsDom = "0.9.2"
    val scalaJsReact = "1.1.1"
    val scalaJsReactComponents = "1.0.0-M1"
  }

  val npmDependencies = Def.setting(Seq(
    "material-ui" -> versions.materialUi,
    "react" -> versions.react,
    "react-dom" -> versions.react
  ))

  val scalaJsDependencies = Def.setting(
    "org.scala-js"                      %%% "scalajs-dom"              % versions.scalaJsDom             ::
    "com.github.japgolly.scalacss"      %%% "core"                     % versions.scalaCSS               ::
    "com.github.japgolly.scalacss"      %%% "ext-react"                % versions.scalaCSS               ::
    "com.github.japgolly.scalajs-react" %%% "core"                     % versions.scalaJsReact           ::
    "com.github.japgolly.scalajs-react" %%% "extra"                    % versions.scalaJsReact           ::
    "com.olvind"                        %%% "scalajs-react-components" % versions.scalaJsReactComponents ::
    Nil
  )
}

Update 1: Changed title and put link to a related issue. It turns out this issue is a bug with webpack.

Update 2: To work around the errors when running fastOptJS::startWebpackDevServer, simply stop using source maps by adding emitSourceMaps := false to your build.sbt. It sucks not having source maps, but to me at least it's better than not having fast, incremental builds.

Zachary Albia
  • 71
  • 2
  • 7

0 Answers0