Skip to content

Scala.js js.dynamicImport always outputs "stub" error #15701

Closed
@hugo-vrijswijk

Description

@hugo-vrijswijk

Compiler version

Any, tested fom 3.0.0 to 3.2.1-RC1-bin-20220717-5c43324-NIGHTLY. Behaviour does not occur on 2.13.8.

Minimized code

import scala.scalajs.js

object Main {
  def main(args: Array[String]): Unit = {
    // Message is dynamically imported and results in a `import(...) call in JS`
    js.dynamicImport {
      println(new Message().msg)
    }
  }
}

class Message {
  def msg = "Hello world dynamic import"
}

Needs some linker config settings to support ES modules. Repro here in a sbt project: https://github.com/hugo-vrijswijk/scala-js-dynamic-import-scala3-bug

Output

[info] Running Main.
<ref *1> $c_jl_Error [java.lang.Error]: stub
    at $c_LMain$.main__AT__V (file:///project/target/scala-3.2.1-RC1-bin-20220717-5c43324-NIGHTLY/hello-world-fastopt/main.mjs:818:27)
    at $s_LMain__main__AT__V (file:///project/target/scala-3.2.1-RC1-bin-20220717-5c43324-NIGHTLY/hello-world-fastopt/main.mjs:804:15)
    at file:///project/target/scala-3.2.1-RC1-bin-20220717-5c43324-NIGHTLY/hello-world-fastopt/main.mjs:1744:1
    at ModuleJob.run (node:internal/modules/esm/module_job:198:25)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:385:24)
    at async importModuleDynamicallyWrapper (node:internal/vm/module:437:15) {
  jl_Throwable__f_s: 'stub',
  jl_Throwable__f_e: null,
  jl_Throwable__f_enableSuppression: true,
  jl_Throwable__f_writableStackTrace: true,
  jl_Throwable__f_stackTraceStateInternal: [Circular *1],
  jl_Throwable__f_stackTrace: null,
  jl_Throwable__f_suppressed: null
}

Scala.JS on Scala 3 emits the line:

  • fastLinkJS: throw $ct_jl_Error__T__(new $c_jl_Error(), "stub")
  • fullLinkJS: throw new $c_jl_Error("stub")

On 2.13.8 the import is emitted as expected.

Expectation

Code runs without error and prints the expected message to the console. sbt ++2.13.x run works as expected, while sbt run gives the error above

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions