I’m new to Kotlin/JS Interoperability and got stuc...
# javascript
y
I’m new to Kotlin/JS Interoperability and got stuck with this error: "Calls to 'js(code)' must be a single expression inside a top-level function body or a property initializer" My code tries to load a WebWorker with js() inside a Koin module, but it’s not allowed. Here’s the problem:
Copy code
actual val platformModule = module {
     single {
         val driver = WebWorkerDriver(
             Worker(
                 js("""new URL("@cashapp/sqldelight-sqljs-worker/sqljs.worker.js", import.meta.url)""") // :x: Error here
             )
         )
         LlmsDatabaseWrapper(driver, LlmsDatabase(driver))
     }
 }
how could I fix this issue?
e
Mmmm, isn't that an error that's used in K/WASM? I don't recall seeing it for usages like that in K/JS.
y
Yes. it is kotlin/wasm. But I think this issue has to do with js interpobality
e
Unfortunately
js()
blocks are more restrictive under K/WASM. What you can do is extract it to a top-level function:
Copy code
private fun sqldelightWorker() =
  js("""new URL("@cashapp/sqldelight-sqljs-worker/sqljs.worker.js", import.meta.url)""")
Which you can then call at its original position:
Copy code
val workerUrl = sqldelightWorker()
...
Worker(workerUrl)
2
y
Thank you for the answer