1

I'm trying to put together a very simple project. It compiles, but when I try to run it, it fails with:

[error] org.scalajs.jsenv.UnsupportedInputException: Unsupported input: List(CommonJSModule(/home/esgott/Repos/onlyco/target/scala-2.12/scalajs-bundler/main/onlyco-fastopt.js))
[error]         at org.scalajs.jsenv.jsdomnodejs.JSDOMNodeJSEnv.$anonfun$validateInput$1(JSDOMNodeJSEnv.scala:59)
[error]         at scala.collection.TraversableLike.$anonfun$map$1(TraversableLike.scala:238)
[error]         at scala.collection.immutable.List.foreach(List.scala:392)
[error]         at scala.collection.TraversableLike.map(TraversableLike.scala:238)
[error]         at scala.collection.TraversableLike.map$(TraversableLike.scala:231)
[error]         at scala.collection.immutable.List.map(List.scala:298)
[error]         at org.scalajs.jsenv.jsdomnodejs.JSDOMNodeJSEnv.validateInput(JSDOMNodeJSEnv.scala:54)
[error]         at org.scalajs.jsenv.jsdomnodejs.JSDOMNodeJSEnv.start(JSDOMNodeJSEnv.scala:35)
[error]         at org.scalajs.sbtplugin.Run$.runInterruptible(Run.scala:44)
[error]         at org.scalajs.sbtplugin.ScalaJSPluginInternal$.$anonfun$scalaJSConfigSettings$49(ScalaJSPluginInternal.scala:438)
[error]         at org.scalajs.sbtplugin.ScalaJSPluginInternal$.$anonfun$scalaJSConfigSettings$49$adapted(ScalaJSPluginInternal.scala:422)
[error]         at scala.Function1.$anonfun$compose$1(Function1.scala:49)
[error] stack trace is suppressed; run last Compile / run for the full output
[error] (Compile / run) org.scalajs.jsenv.UnsupportedInputException: Unsupported input: List(CommonJSModule(/home/esgott/Repos/onlyco/target/scala-2.12/scalajs-bundler/main/onlyco-fastopt.js))

The project code is at https://github.com/esgott/onlyco. I am stuck at debugging this issue, do you have a clue?

esgott
  • 78
  • 8
  • I checked the source code of `scalajs-env-jsdom-nodejs`, and it expects an `Input.Script`, but not an `Input.CommonJSModule`. I wonder what's the difference, and how to align these. – esgott Sep 18 '20 at 15:50

1 Answers1

1

When using scalajs-bundler, as you seem to be doing, it is not enough to specify jsEnv to be a JSDOMNodeJSEnv. Instead, as the reference documentation says, you should use the following scalajs-bundler-specific setting:

requireJsDomEnv in Test := true
sjrd
  • 21,805
  • 2
  • 61
  • 91
  • 1
    I think this is a testing thing, and I have problem with running. Even though I've tried, but it doesn't solve the problem, neither setting it globally, or in `Compile` or `Test` config. – esgott Sep 18 '20 at 15:49
  • No, indeed, `run`ning with the jsdom env is not supported by scalajs-bundler. I'm afraid you're out of luck, although you try to reproduce the effects of `requireJsDomEnv` in the Compile configuration in your own build. The effects are here: https://github.com/scalacenter/scalajs-bundler/blob/2c71d6ff364c619902dcf3613009c9cfc98b38f1/sbt-scalajs-bundler/src/main/scala-sjs-1.x/scalajsbundler/sbtplugin/Settings.scala#L112-L206 – sjrd Sep 18 '20 at 15:57
  • I see, thanks. If `run` is not supported, what is the usual way of trying out an SPA in a browser? I guess there is an obvious way of doing this, but I'm pretty new in this area. – esgott Sep 18 '20 at 16:14
  • 1
    Typically you'd run your server, which would serve the result of `theFrontend/webpack:fastOptJS`. It' fairly rare to want to run the frontend code itself, outside the actual webpage served by the server. – sjrd Sep 18 '20 at 17:36