node.js - TypeError : jsdom. createVirtualConsole 不是函数

标签 node.js scala npm scala.js

我正在尝试构建 basic Scala.js tutorial并且遇到了这个奇怪的错误。

与教程中所示的项目设置没有太大区别,但为了以防万一,这是我的 build.sbt:

enablePlugins(ScalaJSPlugin)

scalaVersion := "2.12.1"

name := "algorithms1_4_34"
version := "1.0"

libraryDependencies ++= Seq("org.scalatest" % "scalatest_2.12" % "3.0.1" % "test",
            "org.scalacheck" %% "scalacheck" % "1.13.4" % "test",
             "org.scala-js" % "scalajs-dom_sjs0.6_2.12" % "0.9.1",
             "be.doeraene" %%% "scalajs-jquery" % "0.9.1")

// This is an application with a main method
scalaJSUseMainModuleInitializer := true

skip in packageJSDependencies := false
jsDependencies +=
  "org.webjars" % "jquery" % "2.1.4" / "2.1.4/jquery.js"
jsDependencies += RuntimeDOM

...和 ​​JSApp 文件:

package ca.vgorcinschi.algorithms1_4_34

import scala.scalajs.js.JSApp
import org.scalajs.jquery.jQuery

object HotAndColdJS extends JSApp{

   def main(): Unit = {
     jQuery(()=>setupUI())
  }

  def addClickedMessage():Unit ={
    jQuery("body").append("<p>You clicked the button!</p>")
  }

  def setupUI():Unit = {
    //click envokes an event handler
    jQuery("#click-me-button").click(()=> addClickedMessage())
    jQuery("body").append("<p>Hello World!</p>")
  }
}

我可以毫无问题地运行compilefastOptJSreloadeclipse(我正在使用 eclipsePlugin)命令.唯一的问题是 run 命令。公平地说,我确实在教程的流程中添加了一些内容,但这只是因为从应用程序的根目录运行此命令 (npm install jsdom) 导致 run 失败好吧(npm WARN enoent ENOENT)。按照建议进行此操作 here我跑了:

npm init
npm install
npm install jsdom

这就是我现在的位置。这是我在使用 run 运行应用程序时遇到的错误:

> run
[info] Running ca.vgorcinschi.algorithms1_4_34.HotAndColdJS
[error] [stdin]:40
[error]     virtualConsole: jsdom.createVirtualConsole().sendTo(console),
[error]                           ^
[error] 
[error] TypeError: jsdom.createVirtualConsole is not a function
[error]     at [stdin]:40:27
[error]     at [stdin]:61:3
[error]     at ContextifyScript.Script.runInThisContext (vm.js:23:33)
[error]     at Object.runInThisContext (vm.js:95:38)
[error]     at Object.<anonymous> ([stdin]-wrapper:6:22)
[error]     at Module._compile (module.js:571:32)
[error]     at evalScript (bootstrap_node.js:391:27)
[error]     at Socket.<anonymous> (bootstrap_node.js:188:13)
[error]     at emitNone (events.js:91:20)
[error]     at Socket.emit (events.js:188:7)
org.scalajs.jsenv.ExternalJSEnv$NonZeroExitException: Node.js with JSDOM exited with code 1
    at org.scalajs.jsenv.ExternalJSEnv$AbstractExtRunner.waitForVM(ExternalJSEnv.scala:107)
    at org.scalajs.jsenv.ExternalJSEnv$ExtRunner.run(ExternalJSEnv.scala:156)
    at org.scalajs.sbtplugin.ScalaJSPluginInternal$.org$scalajs$sbtplugin$ScalaJSPluginInternal$$jsRun(ScalaJSPluginInternal.scala:697)
    at org.scalajs.sbtplugin.ScalaJSPluginInternal$$anonfun$73$$anonfun$apply$48$$anonfun$apply$49.apply(ScalaJSPluginInternal.scala:814)
    at org.scalajs.sbtplugin.ScalaJSPluginInternal$$anonfun$73$$anonfun$apply$48$$anonfun$apply$49.apply(ScalaJSPluginInternal.scala:808)
    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: 4 s, completed 23-May-2017 9:24:20 PM

如果有人能帮我解决这个问题,我将不胜感激。

最佳答案

jsdom v10 引入了一些重大变化。 v9 和 Scala.js <= 0.6.15 没有为这些准备。这就是导致您遇到错误的原因。

升级到 Scala.js 0.6.16 将解决您的问题。它同时支持 jsdom v9 和 v10。

关于node.js - TypeError : jsdom. createVirtualConsole 不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44147662/

相关文章:

node.js - 如何将资源或模板文件包含在 npm 包中,然后将它们加载到 Node 中?

node.js - 如何在多轮中获取 AMAZON.QUERY 输入

javascript - ExpressJS + MongoDB - 登录/注册方法

scala - Scala 中的简单税收计算

javascript - sh : 1: concurrent: not found while npm start

CoffeeScript 不工作 "-bash: coffee: command not found"

node.js - Node.js 服务器无法在共享托管服务器上运行

mysql - 如何使用 Nodejs 和 MySQL 动态自动填充输入字段?

Scala 隐式与隐式参数

scala - 调用 toArray 时编译器错误