Reputation: 33
I have imported scala.sys.process._
into my scala.js project. That alone doesn't cause any problems, but if I add a simple command such as println("ls".!!)
I get a gazillion errors, such as
[error] Referring to non-existent class java.lang.ProcessBuilder
[error] called from scala.sys.process.ProcessCreation.apply(scala.collection.Seq,scala.Option,scala.collection.Seq)scala.sys.process.ProcessBuilder
[error] called from scala.sys.process.Process$.apply(scala.collection.Seq,scala.Option,scala.collection.Seq)scala.sys.process.ProcessBuilder
[error] called from scala.sys.process.ProcessCreation.apply(java.lang.String,scala.Option,scala.collection.Seq)scala.sys.process.ProcessBuilder
[error] called from scala.sys.process.Process$.apply(java.lang.String,scala.Option,scala.collection.Seq)scala.sys.process.ProcessBuilder
[error] called from scala.sys.process.ProcessCreation.apply(java.lang.String)scala.sys.process.ProcessBuilder
[error] called from scala.sys.process.Process$.apply(java.lang.String)scala.sys.process.ProcessBuilder
[error] called from scala.sys.process.ProcessImplicits.stringToProcess(java.lang.String)scala.sys.process.ProcessBuilder
[error] called from scala.sys.process.package$.stringToProcess(java.lang.String)scala.sys.process.ProcessBuilder
[error] called from draw.Main$.main(org.scalajs.dom.raw.HTMLCanvasElement)scala.Unit
[error] called from draw.Main$.$$js$exported$meth$main(org.scalajs.dom.raw.HTMLCanvasElement)java.lang.Object
[error] called from draw.Main$.main
[error] exported to JavaScript with @JSExport
[error] involving instantiated classes:
[error] scala.sys.process.Process$
[error] scala.sys.process.package$
[error] draw.Main$
[error] Referring to non-existent class java.io.File
[error] called from scala.sys.process.ProcessCreation.apply(scala.collection.Seq,scala.Option,scala.collection.Seq)scala.sys.process.ProcessBuilder
[error] called from scala.sys.process.Process$.apply(scala.collection.Seq,scala.Option,scala.collection.Seq)scala.sys.process.ProcessBuilder
[error] called from scala.sys.process.ProcessCreation.apply(java.lang.String,scala.Option,scala.collection.Seq)scala.sys.process.ProcessBuilder
[error] called from scala.sys.process.Process$.apply(java.lang.String,scala.Option,scala.collection.Seq)scala.sys.process.ProcessBuilder
[error] called from scala.sys.process.ProcessCreation.apply(java.lang.String)scala.sys.process.ProcessBuilder
[error] called from scala.sys.process.Process$.apply(java.lang.String)scala.sys.process.ProcessBuilder
[error] called from scala.sys.process.ProcessImplicits.stringToProcess(java.lang.String)scala.sys.process.ProcessBuilder
[error] called from scala.sys.process.package$.stringToProcess(java.lang.String)scala.sys.process.ProcessBuilder
[error] called from draw.Main$.main(org.scalajs.dom.raw.HTMLCanvasElement)scala.Unit
[error] called from draw.Main$.$$js$exported$meth$main(org.scalajs.dom.raw.HTMLCanvasElement)java.lang.Object
[error] called from draw.Main$.main
[error] exported to JavaScript with @JSExport
[error] involving instantiated classes:
[error] scala.sys.process.Process$
[error] scala.sys.process.package$
[error] draw.Main$
[error] Referring to non-existent method java.lang.ProcessBuilder.environment()java.util.Map
Importing extra classes such as java.lang.ProcessBuilder and java.io.File has no impact on the content of these errors. Is there something very simple that I am missing here?
Thanks!
Upvotes: 3
Views: 143
Reputation: 2659
You can't simply import arbitrary Scala libraries into Scala.js -- while the language is the same, the environment is very different. Many standard Scala libraries simply don't exist in the SJS world, and many of them can't, because of the limitations of the JavaScript environment it runs in. It's syntactically legal, so it will compile, but it can't run before there isn't a Scala.js version of the library.
By and large, you should assume that libraries like this don't exist in the SJS world, unless you find that someone has specifically ported it. (I honestly don't know whether someone has ported scala.sys.process
for Node.js; it doesn't make much sense in the browser environment...)
Upvotes: 7