I'm working on converting my ScalaJS 0.6.33 project to 1.x. I started with the transition to 1.0.0, as directed in the documentation. But I got errors that some of my dependencies were compiled with ScalaJS 1.3, so am now attempting to jump to 1.4.0.
My immediate problem is that running tests on my ScalaJS code throws an error originating with node.js:
sbt:xplatform> test
comSetup.js:7
var inBuffer = Buffer.alloc(0);
^
TypeError: Buffer.alloc is not a function
at comSetup.js:7:25
at comSetup.js:61:4
at Object.exports.runInThisContext (vm.js:54:17)
at [stdin]:8:27
at Object.exports.runInThisContext (vm.js:54:17)
at Object.<anonymous> ([stdin]-wrapper:6:22)
at Module._compile (module.js:425:26)
at node.js:587:27
at doNTCallback0 (node.js:428:9)
at process._tickCallback (node.js:357:13)
This is after updating my installation of node to 15.7.0. I note that http://www.scala-js.org/doc/project/js-environments.html says nvm install 5.0
. I tried that first (with the same result). I figured the 5.0 might be a typo, so tried the current version. Same result. I don't know what my previous version of node was.
Any suggestions on how to proceed? Selected lines (not in context!) from plugins.sbt that may be relevant:
addSbtPlugin("com.vmunier" % "sbt-web-scalajs" % "1.1.0")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.4.0")
addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "1.0.0")
addSbtPlugin("org.scala-js" % "sbt-jsdependencies" % "1.0.0")
libraryDependencies += "org.scala-js" %% "scalajs-env-jsdom-nodejs" % "1.1.0"
and what I believe are the relevant parts of build.sbt:
lazy val commonSettings = Seq(
scalaVersion := "2.12.13",
...
)
lazy val xplatform = crossProject(JSPlatform, JVMPlatform)
.crossType(CrossType.Full)
.in(file("_xplatform"))
.settings(commonSettings)
lazy val xplatformJVM = xplatform.jvm
lazy val xplatformJS = xplatform.js
lazy val browser = (project
.in(file("_browser")))
.settings(commonSettings)
.settings(
scalaJSUseMainModuleInitializer := true,
jsEnv := new org.scalajs.jsenv.jsdomnodejs.JSDOMNodeJSEnv(),
libraryDependencies ++= Seq(
"org.scala-js" %%% "scalajs-dom" % "1.1.0"
)
)
.enablePlugins(ScalaJSPlugin, ScalaJSWeb, JSDependenciesPlugin)
.dependsOn(xplatformJS % "test->test;compile->compile")
question from:
https://stackoverflow.com/questions/65927700/node-js-throwing-buffer-alloc-is-not-a-function-error 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…