Skip to content

package --js failed when source contains no main method #3964

@windymelt

Description

@windymelt

Version(s)
scala-cli 1.8.1

Describe the bug
Command scala-cli package --js --js-module-kind es index.scala fails against source code index.scala below:

//> using platform js
//> using scala 3.7

import scala.scalajs.js.annotation.*

object Index {
  @JSExportTopLevel(name = "handler", moduleID = "index")
  def handler(): Unit = {
    println("Hello world!")
  }
}

It results:

Compiling project (Scala 3.7.1, Scala.js 1.19.0)
Compiled project (Scala 3.7.1, Scala.js 1.19.0)
[error]  Error: main.js not found after Scala.js linking (found index.js)

It works when main method is added:

//> using platform js
//> using scala 3.7

import scala.scalajs.js.annotation.*

object Index {
  @JSExportTopLevel(name = "handler", moduleID = "index")
  def handler(): Unit = {
    println("Hello world!")
  }
}

object Hello {
  def main(args: Array[String]): Unit = 42
}

But I need no main method because I just want ESM.

To Reproduce
Run command for same source code.

Expected behaviour

scala-cli can build scala source code without main method using Scala.js.

Metadata

Metadata

Assignees

Labels

Scala.jsbugSomething isn't working

Type

No type

Projects

Status

In progress

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions