This issue happens because non-JVM platforms like wasmJs cannot use type reflection to instantiate ViewModels via the viewModel() function without an explicit initializer.
✅ Fix
Instead of relying on reflection, explicitly create your ViewModel and pass it into your Composable function manually.
✅ Working fix:
fun main {
ComposeViewport(viewportContainerId = "composeApplication") {
val viewModel: MainViewModel = MainViewModel() // ✅ Create instance manually
App(viewModel) // ✅ Pass it in
}
}
📚 Source
JetBrains Docs:
\>"On non-JVM platforms, objects cannot be instantiated using type reflection. So in common > code you cannot call the viewModel() function without parameters."