More Issues with the ScalaJS Tutorial

Dear all,

Proceeding with the ScalaJS basic tutorial:

I faced two issues at steps 5 and 6. Here they are:

  • Step 5: I don’t get any reaction to clicking the button. (For the reference, I am including my Scala file at the P.S. [1].) Everything builds successfully though. Is that the behaviour I should expect?

  • Step 6: After having jsdom installed, I still get a type error when trying run in sbt. The error message can again be found in the P.S. [2]. Relevant to that might be the few warnings I get at the end of jsdom installation. I am putting those in the P.S. too [3]. Any idea what’s going wrong? (Note that I am performing the installation as the admin. So, there is no authentication issue involved.)

TIA,
–Hossein

P.S.

[1] The Scala file:

package tutorial.webapp

import org.scalajs.jquery.jQuery

object TutorialApp {
  def addClickedMessage(): Unit = {
    jQuery("body").append("<p>You clicked the button.</p>")
  }
  
  def setupUI(): Unit = {
    jQuery("#click-me-button").click(() => addClickedMessage())
    jQuery("body").append("<p>Hello World!</p>")
  }

  def main(args: Array[String]): Unit = {
    jQuery(() => setupUI())
  }
}

[2] The run error:

> run
[info] Running tutorial.webapp.TutorialApp
[error] module.js:471
[error] throw err;
[error] ^
[error]
[error] Error: Cannot find module ‘jsdom’
[error] at Function.Module._resolveFilename (module.js:469:15)
[error] at Function.Module._load (module.js:417:25)
[error] at Module.require (module.js:497:17)
[error] at require (internal/module.js:20:19)
[error] at [stdin]:39:13
[error] at [stdin]:67:3
[error] at ContextifyScript.Script.runInThisContext (vm.js:25:33)
[error] at Object.runInThisContext (vm.js:97:38)
[error] at Object. ([stdin]-wrapper:6:22)
[error] at Module._compile (module.js:570:32)
org.scalajs.jsenv.ExternalJSEnv$NonZeroExitException: Node.js with JSDOM exited with code 1
at org.scalajs.jsenv.ExternalJSEnv$AbstractExtRunner.waitForVM(ExternalJSEnv.scala:119)
at org.scalajs.jsenv.ExternalJSEnv$ExtRunner.run(ExternalJSEnv.scala:168)
at org.scalajs.sbtplugin.ScalaJSPluginInternal$.org$scalajs$sbtplugin$ScalaJSPluginInternal$$jsRun(ScalaJSPluginInternal.scala:718)
at org.scalajs.sbtplugin.ScalaJSPluginInternal$$anonfun$73$$anonfun$apply$50$$anonfun$apply$51.apply(ScalaJSPluginInternal.scala:860)
at org.scalajs.sbtplugin.ScalaJSPluginInternal$$anonfun$73$$anonfun$apply$50$$anonfun$apply$51.apply(ScalaJSPluginInternal.scala:854)
at scala.Function1$$anonfun$compose$1.apply(Function1.scala:47)
[trace] Stack trace suppressed: run last compile:run for the full output.
[error] (compile:run) org.scalajs.jsenv.ExternalJSEnv$NonZeroExitException: Node.js with JSDOM exited with code 1
[error] Total time: 2 s, completed 10-Aug-2017 17:53:39

[3] The jsdom installation warnings:

$npm install jsdom
C:\Windows\system32
`– [email protected]
±- [email protected]
±- [email protected]
±- [email protected]
±- [email protected]
±- [email protected]
±- [email protected]
±- [email protected]
±- [email protected]
| ±- [email protected]
| ±- [email protected]
| ±- [email protected]
| ±- [email protected]
| | ±- [email protected]
| | ±- [email protected]
| | ±- [email protected]
| | ±- [email protected]
| | ±- [email protected]
| |\ -- [email protected] |\ [email protected]
| `– [email protected]
±- [email protected]
±- [email protected]
±- [email protected]
| `– @types/[email protected]
±- [email protected]
±- [email protected]
| ±- [email protected]
| ±- [email protected]
| ±- [email protected]
| ±- [email protected]
| |\ -- [email protected] | +-- [email protected] | +-- [email protected] | +-- [email protected] | | \[email protected]
| ±- [email protected]
| | ±- [email protected]
| | | ±- [email protected]
| | | `– [email protected]
| | | `– [email protected]
| |`– [email protected]
| ±- [email protected]
| | ±- [email protected]
| | ±- [email protected]
| | ±- [email protected]
| | `– [email protected]
| ±- [email protected]
| | ±- [email protected]
| | ±- [email protected]
| | | ±- [email protected]
| | | ±- [email protected]
| | | ±- [email protected]
| | | `– [email protected]
| | | ±- [email protected]
| | | -- [email protected] | | \[email protected]
| | ±- [email protected]
| | ±- [email protected]
| | ±- [email protected]
| | ±- [email protected]
| | | `– [email protected]
| | ±- [email protected]
| | ±- [email protected]
| | | `– [email protected]
| | ±- [email protected]
| | `– [email protected]
| ±- [email protected]
| ±- [email protected]
| ±- [email protected]
| ±- [email protected]
| | `– [email protected]
| ±- [email protected]
| ±- [email protected]
| ±- [email protected]
| ±- [email protected]
| ±- [email protected]
| ±- [email protected]
| `– [email protected]
±- [email protected]
| ±- [email protected]
| | `– [email protected]
| `– [email protected]
±- [email protected]
±- [email protected]
±- [email protected]
| `– [email protected]
±- [email protected]
±- [email protected]
| `– [email protected]
±- [email protected]
| ±- [email protected]
| `– [email protected]
`– [email protected]

npm WARN enoent ENOENT: no such file or directory, open ‘C:\Windows\system32\package.json’
npm WARN system32 No description
npm WARN system32 No repository field.
npm WARN system32 No README data
npm WARN system32 No license field.

For the record, I figured out what was wrong in the case of [1]. I had mistakenly replaced the following line in my scalajs-tutorial-fastopt.html

<script type="text/javascript" src="./target/scala-2.12/scala-js-tutorial-fastopt.js"></script>

with

<script type="text/javascript" src="http://cdn.jsdelivr.net/jquery/2.1.1/jquery.js"></script>.

Whereas, I should have added the latter rather than replacing the former with it.

Regarding [2], I’m still getting the same exception on failure to locate jsdom upon run.

Here is more update:

I fixed the npm install jsdom problem using the guidelines provided by Golo Roden here:

But, the problem with calling run from within sbt is still around (even when I run sbt as the admin).