Scala-js: Initialisers for scripts (as opposed to modules)

Created on 17 Apr 2017  路  3Comments  路  Source: scala-js/scala-js

Previously I had:

package japgolly.webapp.client.ww

import scalajs.js.annotation._

@JSExport("Main")
object Main {

  @JSExport
  def main(): Unit = // ...

and in SBT

   scalaJSOutputWrapper := ("", "Main().main();"))

All good.

Now trying to use 0.6.15 with scalaJSModuleKind := NoModule, I can't seem to get it call my main method on initialisation.

The gist of what I've been trying is:

      scalaJSUseMainModuleInitializer := true,
      mainClass := Some("japgolly.webapp.client.ww.Main")

and

      scalaJSUseMainModuleInitializer := true,
      scalaJSMainModuleInitializer := Some(
        org.scalajs.core.tools.linker.ModuleInitializer.mainMethod(
          "shipreq.webapp.client.ww.Main", "main"))

with and without annotations in Main.scala but I can't seem to get it to work.
I keep getting this error:

[error] No main module initializer was specified (possibly because no or multiple main classes were found), but scalaJSUseMainModuleInitializer was set to true. You can explicitly specify it either with `mainClass := Some(...)` or with `scalaJSMainModuleInitializer := Some(...)`
[error] (webapp-client-ww/compile:scalaJSModuleInitializers) No main module initializer was specified (possibly because no or multiple main classes were found), but scalaJSUseMainModuleInitializer was set to true. You can explicitly specify it either with `mainClass := Some(...)` or with `scalaJSMainModuleInitializer := Some(...)`
question

Most helpful comment

Suggestion: It might be better to adjust the error message for this. Currently it says:

You can explicitly specify it either with `mainClass := Some(...)` 

All 3 comments

mainClass in Compile

Ah indeed. Thanks.

Suggestion: It might be better to adjust the error message for this. Currently it says:

You can explicitly specify it either with `mainClass := Some(...)` 
Was this page helpful?
0 / 5 - 0 ratings