In scala.js, what are the possible causes of "Error: Cannot find module 'jsdom'"? - scala

I'm trying to compile and run the scala.js basic tutorial at:
https://github.com/scala-js/scalajs-tutorial
When I execute the main class by sbt run, I got the following error message:
$ sbt run
[info] welcome to sbt 1.6.2 (Private Build Java 1.8.0_312)
[info] loading global plugins from /home/xxx/.sbt/1.0/plugins
[info] loading settings for project scalajs-tutorial-build from plugins.sbt ...
[info] loading project definition from /home/xxx/git-release/scalajs-tutorial/project
[info] loading settings for project scalajs-tutorial from build.sbt ...
[info] set current project to Scala.js Tutorial (in build file:/home/xxx/git-release/scalajs-tutorial/)
[info] Running tutorial.webapp.TutorialApp.
node:internal/modules/cjs/loader:936
throw err;
^
Error: Cannot find module 'jsdom'
Require stack:
- /home/xxx/git-release/scalajs-tutorial/[stdin]
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at codeWithJSDOMContext.js:3:15
at codeWithJSDOMContext.js:52:3
at Script.runInThisContext (node:vm:129:12)
at Object.runInThisContext (node:vm:305:38)
at [stdin]:2:29
at Script.runInThisContext (node:vm:129:12) {
code: 'MODULE_NOT_FOUND',
requireStack: [ '/home/xxx/git-release/scalajs-tutorial/[stdin]' ]
}
[error] org.scalajs.jsenv.ExternalJSRun$NonZeroExitException: exited with code 1
[error] at org.scalajs.jsenv.ExternalJSRun$$anon$1.run(ExternalJSRun.scala:195)
[error] stack trace is suppressed; run last Compile / run for the full output
[error] (Compile / run) org.scalajs.jsenv.ExternalJSRun$NonZeroExitException: exited with code 1
[error] Total time: 3 s, completed 28-Feb-2022 12:57:35 AM
What's the cause of it and how do I fix it?

The problem is most likely that you did not install jsdom for your project. You can do so by running
$ npm install jsdom
in the directory where you launch sbt.

Related

How can I get the Scala .js 1.3.0 tutorial to run - part 2?

After moving the project to my local files system on C: now I am getting
sbt:Scala.js Tutorial> run
[warn] There may be incompatibilities among your library dependencies; run 'evicted' to see detailed eviction warnings.
[info] Compiling 1 Scala source to C:\Users\ERIC\Documents\git\scalajs-tutorial\target\scala-2.13\classes ...
[info] Fast optimizing C:\Users\ERIC\Documents\git\scalajs-tutorial\target\scala-2.13\scala-js-tutorial-fastopt
[info] Running tutorial.webapp.TutorialApp. Hit any key to interrupt.
internal/modules/cjs/loader.js:834
throw err;
^
Error: Cannot find module 'jsdom'
Require stack:
- C:\Users\ERIC\Documents\git\scalajs-tutorial\[stdin]
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:831:15)
at Function.Module._load (internal/modules/cjs/loader.js:687:27)
at Module.require (internal/modules/cjs/loader.js:903:19)
at require (internal/modules/cjs/helpers.js:74:18)
at codeWithJSDOMContext.js:3:15
at codeWithJSDOMContext.js:52:3
at Script.runInThisContext (vm.js:120:18)
at Object.runInThisContext (vm.js:309:38)
at [stdin]:2:29
at Script.runInThisContext (vm.js:120:18) {
code: 'MODULE_NOT_FOUND',
requireStack: [ 'C:\\Users\\ERIC\\Documents\\git\\scalajs-tutorial\\[stdin]' ]
}
[error] org.scalajs.jsenv.ExternalJSRun$NonZeroExitException: exited with code 1
[error] at org.scalajs.jsenv.ExternalJSRun$$anon$1.run(ExternalJSRun.scala:186)
[error] stack trace is suppressed; run last Compile / run for the full output
[error] (Compile / run) org.scalajs.jsenv.ExternalJSRun$NonZeroExitException: exited with code 1
[error] Total time: 6 s, completed Oct. 16, 2020, 9:53:33 a.m.
Also
sbt:Scala.js Tutorial> evicted
[warn] Found version conflict(s) in library dependencies; some are suspected to be binary incompatible:
[warn] * org.scala-js:scalajs-library_2.13:1.3.0 is selected over 1.0.0
[warn] +- scala-js-tutorial:scala-js-tutorial_sjs1_2.13:0.1.0-SNAPSHOT (depends on 1.3.0)
[warn] +- org.scala-js:scalajs-dom_sjs1_2.13:1.1.0 (depends on 1.0.0)
[success] Total time: 0 s, completed Oct. 16, 2020, 10:18:13 a.m.
Has Scala.js 1.3.0 been tested with the tutorial at (https://github.com/scala-js/scalajs-tutorial)
yet?
It's kinda buried, but the tutorial linked from the repo mentions that you need to install jsdom separately:
This will use the jsdom library to simulate a DOM in Node.js. Note that you need to install it separately using
$ npm install jsdom
After reloading, you can invoke run successfully

How to run an existing Scala project using VS Code and Metals?

I am brand new to Scala and I find that Scala IDE is very slow on my machine for basic things like searching the codebase and editing code. I am used to Visual Studio Code and was very happy to find this metals extension.
I was able to "import build" and fix issues like bumping up scala version in my projects but I am not sure how to reproduce this step to set up a run configuration and actually launch our app in Scala IDE.
We have a parent folder which has a bunch of projects and a 'consoleapp' project which is the main entry point of our app - it imports the logic/routes of all other projects.
|____parent
| |____consoleapp
| |____project1
| |____project2
I tried sbt run and sbt runMain consoleapp from within the consoleapp folder and also the parent folder but they didn't work.
I am not sure what other information from our setup is relevant - happy to provide more info as needed.
Updated to add more details below:
consoleapp/build.sbt
name := "consoleapp"
version := "1.0"
scalaVersion := "2.12.10"
packMain := Map("consoleapp" -> "consoleapp")
libraryDependencies ++= Seq (...)
Output of commands I ran - sbt run and sbt runMain
Running from ~/scala/parent
> sbt run masterstate [0a8dab85] modified
[info] Loading settings for project global-plugins from metals.sbt,build.sbt ...
[info] Loading global plugins from /Users/pradhyo/.sbt/1.0/plugins
[info] Loading project definition from /Users/pradhyo/scala/parent/project
[info] Loading settings for project consoleapp from build.sbt ...
...
Loading settings for all other projects in parent folder
...
[info] Loading settings for project parent from build.sbt ...
[info] Resolving key references (22435 settings) ...
[info] Set current project to parent (in build file:/Users/pradhyo/scala/parent/)
[error] java.lang.RuntimeException: No main class detected.
[error] at scala.sys.package$.error(package.scala:30)
[error] stack trace is suppressed; run last Compile / bgRun for the full output
[error] (Compile / bgRun) No main class detected.
[error] Total time: 1 s, completed 18-Dec-2019 1:41:25 PM
Running from ~/scala/parent
> sbt "runMain consoleapp.consoleapp" masterstate [0a8dab85] modified
[info] Loading settings for project global-plugins from metals.sbt,build.sbt ...
[info] Loading global plugins from /Users/pradhyo/.sbt/1.0/plugins
[info] Loading project definition from /Users/pradhyo/scala/parent/project
[info] Loading settings for project consoleapp from build.sbt ...
...
Loading settings for all other projects in parent folder
...
[info] Loading settings for project parent from build.sbt ...
[info] Resolving key references (22435 settings) ...
[info] Set current project to parent (in build file:/Users/pradhyo/scala/parent/)
[info] running consoleapp.consoleapp
[error] (run-main-0) java.lang.ClassNotFoundException: consoleapp.consoleapp
[error] java.lang.ClassNotFoundException: consoleapp.consoleapp
[error] at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
[error] stack trace is suppressed; run last Compile / bgRunMain for the full output
[error] Nonzero exit code: 1
[error] (Compile / runMain) Nonzero exit code: 1
[error] Total time: 0 s, completed 18-Dec-2019 1:46:21 PM
Running from ~/scala/parent/consoleapp
> sbt run masterstate [0a8dab85] modified
[info] Loading settings for project global-plugins from metals.sbt,build.sbt ...
[info] Loading global plugins from /Users/pradhyo/.sbt/1.0/plugins
[info] Loading project definition from /Users/pradhyo/scala/parent/consoleapp/project
[info] Loading settings for project consoleapp from build.sbt ...
[info] Set current project to consoleapp (in build file:/Users/pradhyo/scala/parent/consoleapp/)
[error] java.lang.RuntimeException: No main class detected.
[error] at scala.sys.package$.error(package.scala:30)
[error] stack trace is suppressed; run last Compile / bgRun for the full output
[error] (Compile / bgRun) No main class detected.
[error] Total time: 0 s, completed 18-Dec-2019 1:49:26 PM
Running from ~/scala/parent/consoleapp
> sbt "runMain consoleapp" masterstate [0a8dab85] modified
[info] Loading settings for project global-plugins from metals.sbt,build.sbt ...
[info] Loading global plugins from /Users/pradhyo/.sbt/1.0/plugins
[info] Loading project definition from /Users/pradhyo/scala/parent/consoleapp/project
[info] Loading settings for project consoleapp from build.sbt ...
[info] Set current project to consoleapp (in build file:/Users/pradhyo/scala/parent/consoleapp/)
[info] running consoleapp
[error] (run-main-0) java.lang.ClassNotFoundException: consoleapp
[error] java.lang.ClassNotFoundException: consoleapp
[error] at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
[error] stack trace is suppressed; run last Compile / bgRunMain for the full output
[error] Nonzero exit code: 1
[error] (Compile / runMain) Nonzero exit code: 1
[error] Total time: 1 s, completed 18-Dec-2019 1:50:06 PM
After following the instructions in the Scala Metals VSCode Readme, use a launch configuration similar to this for the Eclipse screenshots in the question.
.vscode/launch.json
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "scala",
"name": "Debug consoleapp",
"request": "launch",
"mainClass": "consoleapp",
"buildTarget": "consoleapp",
"args": [],
"jvmOptions": ["-J-Dconfig.file=/path/to/config/file"]
}
]
}
I had trouble passing the config file for pureconfig correctly. Here's the Github issue with the correct jvmOptions line.
Metals supports these Scala versions 2.13.0, 2.13.1, 2.12.8, 2.12.9,
2.12.10, 2.12.7 and 2.11.12
This is something I noticed from their documentation(doc). So it could pinpoint to your and mine problem which I addressed in comments.
Your scalaVersion := "2.12.3" is not listed here.

sbt Hello World raising UnknownFormatConversionException: Conversion = '0'

I tried to create a hello world following instructions given in the sbt-documentation.
$ sbt new sbt/scala-seed.g8
WARN: No sbt.version set in project/build.properties, base directory: /Users/pankaj/Work/Code/learn
[warn] Executing in batch mode.
[warn] For better performance, hit [ENTER] to switch to interactive mode, or
[warn] consider launching sbt without any commands, or explicitly passing 'shell'
[info] Set current project to learn (in build file:/Users/pankaj/Work/Code/learn/)
Minimum Scala build.
name [My Something Project]: hello
Template applied in ./hello
$
Now I go into the "hello" directory just created and run "sbt".
$ sbt
[info] Loading project definition from /Users/pankaj/Work/Code/learn/hello/project
[info] Updating {file:/Users/pankaj/Work/Code/learn/hello/project/}hello-build...
[info] Resolving org.scala-sbt.ivy#ivy;2.3.0-sbt-2cf13e211b2cb31f0d3b317289dca70[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
[info] Compiling 1 Scala source to /Users/pankaj/Work/Code/learn/hello/project/target/scala-2.10/sbt-0.13/classes...
java.util.UnknownFormatConversionException: Conversion = '0'
at java.util.Formatter.checkText(Formatter.java:2579)
at java.util.Formatter.parse(Formatter.java:2565)
at java.util.Formatter.format(Formatter.java:2501)
…
…
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:748)
[error] (compile:compile) java.util.UnknownFormatConversionException: Conversion = '0'
Project loading failed: (r)etry, (q)uit, (l)ast, or (i)gnore? q
$
First, I am clueless why the build tool is using scala-2.10, when the generated build.sbt file has "scalaVersion" 2.12.1 specified under "inThisBuild" settings.
Second, and the main issue is, how to debug and fix the
UnknownFormatConversionException: Conversion = '0'
Not sure how to get past the "Hello, World!" example.

Scalc SBT compile failing

I am trying to follow code from below link
http://spark.apache.org/docs/latest/quick-start.html
But when I am trying to create package it is failing. I want to know 2 thinks
obviously, why it is failing
why it is showing older version of the scala, while I mentioned 2.11
Below is the error message.
[info] Set current project to default-0464ce (in build file:/home/ubuntu/simple_sbt/)
[info] Updating {file:/home/ubuntu/simple_sbt/}default-0464ce...
[info] Resolving org.scala-lang#scala-library;2.9.1 ...
[info] Done updating.
[info] Compiling 1 Scala source to /home/ubuntu/simple_sbt/target/scala-2.9.1/classes...
[error] /home/ubuntu/simple_sbt/src/main/scala/SimpleApp.scala:1: object apache is not a member of package org
[error] import org.apache.spark.SparkContext
[error] ^
[error] /home/ubuntu/simple_sbt/src/main/scala/SimpleApp.scala:2: object apache is not a member of package org
[error] import org.apache.spark.SparkContext._
[error] ^
[error] two errors found
[error] {file:/home/ubuntu/simple_sbt/}default-0464ce/compile:compile: Compilation failed
[error] Total time: 2 s, completed Aug 30, 2016 3:19:18 AM
when you run sbt package , sometimes it fails as there are no dependencies that are downloaded and will be resolved for the files imported.
Try running, sbt run first and then sbt package . sbt run should bring in all the dependencies on top of which packaging and compiling will be possible.
If the above does not solves your problem, you need to share your sbt build file and the environment that you are using. In which directory you are running these commands, will also play a role.

I couldn't import 'Existing Maven Projects' of i-jetty

They said,
cd $IJETTY_HOME/console
mvn clean install
This will produce a war file in $IJETTY_HOME/console/webapp/target, and also the apk in $IJETTY_HOME/console/apk/target (although as we mentioned, you're probably not interested in that).
but I got following error (...oh, my god. I can not upload image ;0 )
**
[INFO] --- exec-maven-plugin:1.2:exec (generate-dex) # console ---
Unable to access jarfile ${env.ANDROID_HOME}/platform-tools/lib/dx.jar
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] I-Jetty :: Console Parent ......................... SUCCESS [0.241s]
[INFO] I-Jetty :: Console Webapp ......................... FAILURE [2.431s]
[INFO] I-Jetty :: Console Android Installer .............. SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.122s
[INFO] Finished at: Thu Nov 08 19:33:47 KST 2012
[INFO] Final Memory: 14M/81M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2:exec (generate-dex) on project console: Command execution failed. Process exited with an error: 1(Exit value: 1) -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR] mvn <goals> -rf :console**
and I tried 'Building with Eclipse'
finally, I got following error similar with the one.
on Import Maven Projects,
exec-maven-plugin:1.2:exec (1 errors)
maven-antrun-plugin:1.6:run(1 errors)
maven-depoendency-plugin:2.3:unpack-dependencies(1 error)
Help me, plz.
I installed maven plug-in 1.3 with eclipse on Mac OS X Lion.
finally, I solved it by myself.
I missed export android sdk path (export ANDROID_HOME=/opt/android/android-sdk-linux_86)
and I edited pom.xml
from
<artifactId>maven-android-plugin</artifactId>
<version>2.9.0-beta-5</version>
to
<artifactId>android-maven-plugin</artifactId>
<version>3.0.0</version>
thanks.