You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Full runnable project with this code and instructions on how to run scala.js + vite is available in the attached .zip archive.
Main.scala
packageexampleimportorg.scalajs.domimportscala.annotation.nowarnimportscala.scalajs.js@nowarn inlinedefdynamicImport[F](inlinef: F): js.Promise[F] = {
js.dynamicImport(f)
}
@main defmain():Unit=
js.timers.setTimeout(2000) {
val_= js.dynamicImport({ dom.console.log("THIS IS js.dynamicImport") })
val_= dynamicImport({ dom.console.log("THIS IS local dynamicImport") }) // this throws// val _ = Importer.dynamicImport({ dom.console.log("THIS IS Importer.dynamicImport") }) // this throws after `sbt clean` only
}
dom.document.querySelector("#app").innerText ="Scala.js loaded. Open browser console to see `stub` error."
Uncaught java.lang.Error: stub
...
THIS IS js.dynamicImport
Expectation
Browser console at runtime:
THIS IS js.dynamicImport
THIS IS local dynamicImport
One more failure mode
In addition to the local dynamicImport never working, there is another, intermittent failure mode when the dynamicImport method is placed in a separate file (Importer.scala). Steps to reproduce that particular mode:
comment out the line with the local dynamicImport
uncomment the line with Importer.dynamicImport
run sbt clean
run the project as usual with ~fastLinkJS and npm run dev
you will see the same stub error in the browser console
add an empty // comment in Main.scala
after Vite reloads the page, the stub error is gone, and Importer.dynamicImport works as expected, printing out THIS IS Importer.dynamicImport
if you do sbt clean again, the error comes back on the next compile.
Compiler version
3.3.4, 3.5.2, 3.6.4-RC1-bin-20241205-c61897d-NIGHTLY
Minimized code
Full runnable project with this code and instructions on how to run scala.js + vite is available in the attached .zip archive.
Main.scala
Importer.scala
build.sbt (extract)
Output
Browser console at runtime:
Expectation
Browser console at runtime:
One more failure mode
In addition to the local
dynamicImport
never working, there is another, intermittent failure mode when thedynamicImport
method is placed in a separate file (Importer.scala). Steps to reproduce that particular mode:dynamicImport
Importer.dynamicImport
sbt clean
~fastLinkJS
andnpm run dev
stub
error in the browser console//
comment in Main.scalastub
error is gone, andImporter.dynamicImport
works as expected, printing outTHIS IS Importer.dynamicImport
sbt clean
again, the error comes back on the next compile.Full project
The text was updated successfully, but these errors were encountered: