scalajs-bundler在源地图URL上窒息前缀为本地路径,例如运行fastOptJS :: startWebpackDevServer时'./http ...'源文件

时间:2017-11-25 09:17:25

标签: webpack sbt scala.js scalajs-bundler

我有一个ScalaJS项目并在Windows 10中运行sbt命令fastOptJS::startWebpackDevServer会产生错误,如下面的代码段所示:

[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:更改了标题并将链接放到相关的issue。事实证明这个问题是webpack的一个错误。

更新2:要在运行fastOptJS::startWebpackDevServer时解决错误,只需将emitSourceMaps := false添加到build.sbt即可停止使用源地图。它糟透了没有源映射,但对我来说至少它比没有快速增量构建更好。

0 个答案:

没有答案