我有一个 ScalaJS 项目并fastOptJS::startWebpackDevServer
在 Windows 10 中运行 sbt 命令会产生如下代码段中的错误:
[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
这很奇怪,因为它尝试从当前目录解析 URL,如本部分所示:Error: Can't resolve './https://raw.githubusercontent.com/scala/scala/v2.12.4/src/library/scala/util/control/Breaks.scala'
我也尝试过运行fastOptJS::webpack
,而不是错误它会产生警告。
这是我的 build.sbt 文件:
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)
和 Settings.scala 文件:
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
)
}
更新 1:更改标题并将链接放入相关问题。事实证明,这个问题是 webpack 的一个错误。
更新 2:要解决运行时的错误,只需通过添加到 build.sbt 来fastOptJS::startWebpackDevServer
停止使用源映射。emitSourceMaps := false
没有源映射很糟糕,但至少对我来说,这比没有快速的增量构建要好。