https://kotlinlang.org logo
#webassembly
Title
# webassembly
r

Robert Jaros

10/14/2023, 5:31 PM
I'm getting errors when trying to run tests with some NPM dependencies, e.g. when using
kotlinx.datetime
I've got:
Copy code
> Task :wasmJsBrowserTest
404: /absolute/tmp/_karma_webpack_461787/node_modules_js-joda_core_dist_js-joda_esm_js.js
  (error: /tmp/_karma_webpack_461787/node_modules_js-joda_core_dist_js-joda_esm_js.js)
      at __webpack_require__.f.j (/tmp/_karma_webpack_461787/runtime.js:300:29)
      at /tmp/_karma_webpack_461787/runtime.js:161:40
      at Array.reduce (<anonymous>)
      at __webpack_require__.e (/tmp/_karma_webpack_461787/runtime.js:160:67)
      at instantiate (<webpack://kilua-wasm-js-test/./kotlin/kilua-wasm-js-test.uninstantiated.mjs?:17:93>)
      at eval (<webpack://kilua-wasm-js-test/./kotlin/kilua-wasm-js-test.mjs?:9:156>)
      at __webpack_require__.a (/tmp/_karma_webpack_461787/runtime.js:91:13)
      at eval (<webpack://kilua-wasm-js-test/./kotlin/kilua-wasm-js-test.mjs?:1:21>)
      at ./kotlin/kilua-wasm-js-test.mjs (load.286322405.js:18:1)
      at Function.__webpack_require__ (/tmp/_karma_webpack_461787/runtime.js:31:41)
I'm on Kotlin 1.9.20-Beta2.
This is a bit similar https://youtrack.jetbrains.com/issue/KT-62128/Wasm-tests-still-do-not-work-on-Kotlin-1.9.20-Beta2, but the workaround is not working for me.
i

Ilya Goncharov [JB]

10/16/2023, 1:57 PM
Hi, in this issue problem is with Windows paths. In your case JS dependencies should be bundled via
webpack
, but looks like it doesn’t. So probably it is another problem. As I understand it is because webpack processing all dynamic imports as separate files. But Karma has problem with emitting more than one file from webpack. So I will investigate how we can fix Karma in such cases
🙏 1
@Robert Jaros Hi, looks like I found root cause of the problem. It is because configuration of webpack inside Karma (precisely
optimization
field). It is necessary source maps to work correctly. But it is more actual for Kotlin/JS. So in Kotlin/Wasm I think it can be deleted (yes, source maps will be wrong in such case in Kotlin/Wasm) Workaround is following: create
karma.config.d
to create custom script inside Karma config. Create file under this folder, for example
index.js
with content
Copy code
delete config.webpack.optimization
It should fix problem with loading of separate files for testing purposes. Just as additional information, I understand the reason why
karma
needs its own
optimization
setting, and looks like I understand how it can be possible to work source maps with their setup, so I hope it will work in next releases.
r

Robert Jaros

10/19/2023, 11:26 AM
Thank you! The workaround works perfectly 🙂
👍 1