Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
hugo-vrijswijk opened this issue Jul 18, 2022 · 1 comment
Closed

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

hugo-vrijswijk opened this issue Jul 18, 2022 · 1 comment

Comments

@hugo-vrijswijk
Copy link
Contributor

hugo-vrijswijk commented Jul 18, 2022

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

@hugo-vrijswijk hugo-vrijswijk added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Jul 18, 2022
@sjrd
Copy link
Member

sjrd commented Jul 18, 2022

Yeah, I don't think we've implemented js.dynamicImport in Scala 3 yet. 😳

@sjrd sjrd self-assigned this Jul 18, 2022
@sjrd sjrd changed the title Scala.JS js.dynamicImport always outputs "stub" error Scala.js js.dynamicImport always outputs "stub" error Jul 18, 2022
@szymon-rd szymon-rd added area:scala.js and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Jul 19, 2022
sjrd added a commit to dotty-staging/dotty that referenced this issue Jul 21, 2022
@sjrd sjrd closed this as completed in 2c260e0 Jul 23, 2022
sjrd added a commit that referenced this issue Jul 23, 2022
Fix #15701: Implement js.dynamicImport for dynamic module loading.
@sjrd sjrd added this to the 3.2.1-RC1 milestone Jul 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants