Hey, I am migrating a multiplatform project from 1...
# javascript
b
Hey, I am migrating a multiplatform project from 1.3.72 to 1.4. However I am running into an issue with trying to run kotlinjs "browser" output in a web worker context:
Copy code
Uncaught ReferenceError: window is not defined
    at universalModuleDefinition:10
    at workerLocal.js:15
I understand that window is not a defined object in a web worker context, and my own code avoids using it. But the module loader seems to try to access it. This was not an issue with 1.3.72, and I hope there are some config options I could tweak to get it to work. Hope I can get some help on this as I dont know how to proceed on my on my own.
i
Hi, it can be related with fact, that webpack by default write all public API in
window
context You can try next WAs, I am not sure, why it was not issue Create
webpack.config.d
folder Create js file in it
Copy code
config.globalObject = this
If it does not help, you can try write next thing instead of previous one (https://webpack.js.org/configuration/output/#outputlibrarytarget)
Copy code
config.output = config.output || {}
config.output.libraryTarget = 'var'
b
Thanks for the response! Trying the fist suggestion resulted in
Copy code
> Task :jsBrowserProductionWebpack FAILED

Execution failed for task ':jsBrowserProductionWebpack'.
> java.lang.IllegalStateException (no error message)
I am not sure if I could get more information about the exception, that's all that it provided. Second suggestion seems to have fixed the initial error, but results in another error:
Copy code
Uncaught ReferenceError: HTMLDivElement is not defined
    at Object.n (gen-consumer-tags-js.kt:183)
    at Object.<anonymous> (output.js:1)
    at r (bootstrap:19)
    at Object.<anonymous> (output.js:1)
    at r (bootstrap:19)
    at bootstrap:83
    at output.js:1
    at workerLocal.js:11
I think this may be caused by
org.jetbrains.kotlinx:kotlinx-html-js
which my projects includes but does not use inside the webworker.
Seems like making a dummy HTMLDivElement class in the webworker context before loading the kotlin module fixed the issue, albeit in a very hacky way. Not sure why it's only that particular element that's undefined. Thank you for the helpful response.
r
You can also add this to the build file instead of adding a webpack config (for the window problem in webworker):
Copy code
browser {
    webpackTask {
        output.libraryTarget = VAR
    }
}
👍 1
👌 1