https://kotlinlang.org logo
#squarelibraries
Title
# squarelibraries
n

Nick Williams

09/14/2023, 8:44 AM
And I fixed that one by changing the code in https://cashapp.github.io/sqldelight/2.0.0/js_sqlite/#using-a-web-worker from
Copy code
val driver = WebWorkerDriver(
  Worker(
    js("""new URL("@cashapp/sqldelight-sqljs-worker/sqljs.worker.js", import.meta.url)""")
  )
)
to
Copy code
val driver = WebWorkerDriver(
  Worker(
    js("""new URL("@cashapp/sqldelight-sqljs-worker/sqljs.worker.js", import.meta.url)"""),
    object : WorkerOptions { override var type: WorkerType? = WorkerType.MODULE }
  )
)
but I think this is now causing
SyntaxError: ambiguous indirect export: default
which I assume is because
sqljs.worker.js
isn't a module after all - how is the
import initSqlJs from "sql.js";
at the top of the file suppose to work? Is webpack suppose to make this import go away during bundling? @Derek Ellis
d

Derek Ellis

09/21/2023, 8:06 PM
I think webpack might treat it differently than vite does.
(assuming you are using vite based on your previous messages?)
m

Marco Gomiero

01/25/2024, 4:23 PM
@Nick Williams Were you able to solve it? I'm in a similar situation with vite. I've modified the Worker instantiation but it's brutally failing and I can't understand why 😓
Copy code
actual suspend fun createDriver(): SqlDriver {
            console.log("before worker instance")

            val driver =  WebWorkerDriver(
//                Worker(
//                    js("""new URL("@cashapp/sqldelight-sqljs-worker/sqljs.worker.js", import.meta.url)""")
//                )
                // TODO: revert back, this is for vite
                Worker(
                    js("""new URL("@cashapp/sqldelight-sqljs-worker/sqljs.worker.js", import.meta.url)"""),
                    object : WorkerOptions {
                        override var type: WorkerType? = WorkerType.MODULE
                    }
                ).apply {
                    onerror = {
                        console.log("Error in workerr: ", it)
                    }

                    onmessage = {
                        console.log("on message: ", it)
                    }
                }
            )

            console.log("after worker instance")
            console.log("bbhere")

            // Crashing here :(
            try {
                HockeyDb.Schema.awaitCreate(driver)
            } catch (e: Throwable) {
                console.log("Error in awaitCreate: ", e)
            }

            console.log("after driver creation")

            return driver
        }