Hi! I have a KMP library imported to a LightningJs...
# javascript
c
Hi! I have a KMP library imported to a LightningJs (https://lightningjs.io) project. The library is exported and then imported to the LightningJs project using a private npm registry. For the following code
Copy code
@OptIn(DelicateCoroutinesApi::class)
fun testFunctionInline(): Promise<String> =
    GlobalScope.promise(Dispatchers.Default) {
        return@promise "hello with inline"
    }
I get the this error
Copy code
Uncaught (in promise) TypeError: parentContext.q3 is not a function
at DeferredCoroutine.AbstractCoroutine (as constructor (index-1da9d773.s:124914133)
at new DeferredCoroutine (<http://index-1da9d773.is|index-1da9d773.is>: 125056:27)
at async index-1da9d773 15 124993 86)
at promise (index-1da9d773.5:128534:26)
at protoot2. testFunctionIn line (index-1da9d773.15:135390:14)
at Object. testKmpLib (index-1da9d773.1s:136760:29)
_ConfigService index-1da9d773.15:136742:15
at index-1da9d773.js:136860:23
If I use with a ReactJs project, its working. Any idea what is the problem?
a
Hi, what the compiler version do you use?
c
Hi. 1.8.22
a
Could you try please if it will work with 1.9.0 or 1.9.10?
c
I tried but it still not working. I also tried with a new project and it worked. So I'm not sure why its not working with any project but creating a new project is not an option for me.
a
Hmm, I see. Could you also provide a bit more information. What do you mean when you say "exported and imported"? Do you try to use your declarations on the JS side?
c
I think its not important, but after build I publish it to a private npm registry (
npm publish
) and I add the library to the JsProject with
npm install
. I also observed that this issue happens only when there are 2 KMP projects imported to the same JS project. Both using GlobalScope.promise(). I am not completely sure how it works, but maybe here is the problem. The stack trace also points to CoroutineScope.async() function which is called when using GlobalScope.promise.
CoroutineScope(Dispatchers.Unconfined).promise solved the issue.
a
Hmmm. Interesting
j
@Császár Ákos have you managed to resolve the issue? I am facing the same case in my side project 😞
c
Yes. Instead of
GlobalScope.promise(Dispathers.Default)
I am using
CoroutineScope(Dispatchers.Unconfined).promise
j
Thank you, I will check and let you know!
👍 1