-
Notifications
You must be signed in to change notification settings - Fork 1.9k
"Uncaught TypeError: Cannot read property 'context' of undefined" when compiling to JS #1145
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
Comments
What version of Kotlin Compiler and library are you using? |
Kotlin 1.3.30, Coroutines 1.2.0 btw I ended up solving this by using Javascript Workers instead, for anyone reaching here from Google |
Do you have a self-contained example with problem to file a bug for JS compiler? It does not seem to be related to #325, though, since thing code does not seem to have any suspend properties or do you use them somewhere else? |
Closing as outdated |
I hope this helps some googler since this ticket is the top result for the error message Using Kotlin 1.3.41 and Coroutines 1.3.20M2 An example Kotlin function: suspend fun doStuff(/*note! no function arguments here*/) {
println("printed from the Frontend Kotlin File")
} will get compiled to this function doStuff(continuation_0, suspended) {
var instance = new Coroutine$main(continuation_0);
if (suspended)
return instance;
else
return instance.doResume(null);
} The second to last parameter of a suspend function in Javascript is apparently a coroutine continuation, While debugging you can see that the myapp.doStuff(kotlin.kotlin.coroutines.js.internal.EmptyContinuation); Cheers and all the best, |
Actually, there is a much much better way Wrap your Kotlin function in a javascript promise fun doStuff(): Promise<String> = //or Promise<Unit> for voids
GlobalScope.promise {
callToActualSuspendFunction() // return a String
} output.doStuff().then(function(returnValue) {
alert (returnValue);
}); source: https://discuss.kotlinlang.org/t/how-do-i-call-coroutines-from-javascript/12098/2 |
How did you get this error message? By trying to invoke suspend function from javascript and passing |
Hi @qwwdfsad,
Well, probably yes (my JS-Fu is not at 100% ;-)). |
I reproduced the issue in https://github.com/boyvanduuren/reproducer. The kotlin is already compiled to JS in there, but you can recompile if you want. The issue is demonstrated by running |
Thanks. I've reposted it here: https://youtrack.jetbrains.com/issue/KT-32708 |
Hi everyone, |
seems similar to this, but the link is dead: #352
Error:
I might be doing something wrong or this might be a bug
Is there any workaround for this
The text was updated successfully, but these errors were encountered: