Kotlin JS + coroutines -> Uncaught ReferenceError: CoroutineImpl is not defined


  • kotlin: 1.3.0-rc-51
  • kotlinx-coroutines: 0.26.1-eap13

I have a simple global function:

suspend inline fun function(){

The generated JS code fails at runtime:

  Coroutine$function.$metadata$ = {
    kind: Kotlin.Kind.CLASS,
    simpleName: null,
    interfaces: [CoroutineImpl] // "Uncaught ReferenceError: CoroutineImpl is not defined"

Other parts of the generated JS code initialize the CoroutineImpl variable correctly like

var CoroutineImpl = Kotlin.kotlin.coroutines.CoroutineImpl;

I think this is a bug and I found no workaround…
What do you think?

I found a workaround.

I have a multi-platform / multi-module project where there are two kotlin-js modules:

  • utility-js: the suspendable function is declared here
  • app-js (depends on utility-js): the suspendable function is called from this module

When I moved function’s declaration to the app-js module then everything works as expected, the generated JS code now contains

var CoroutineImpl = Kotlin.kotlin.coroutines.CoroutineImpl;

at the beginning of the generated JS code.

This problem still exists in 1.3.0-rc-146 :frowning:

Can you submit the issue to the tracker? A sample project would be also very helpful.
Thank you!

I’ve submitted the issue: https://youtrack.jetbrains.com/issue/KT-27611

Thank you! Will take a look