Another question. I’m trying to run a compose wasm...
# webassembly
l
Another question. I’m trying to run a compose wasmJs app and I was getting the error
process is not defined
on both js and wasmJs targets so I added:
Copy code
// webpack.config.d/plugins.ks
const webpack = require('webpack');

config.plugins.push(
    new webpack.ProvidePlugin({
        process: require.resolve('process/browser'),
    }),
);
That fixes the js target. But now for wasmJs I get
TypeError: process.release is undefined
Is this expected?
I also tried to fix that error by doing:
Copy code
const webpack = require('webpack');

config.plugins.push(
    new webpack.ProvidePlugin({
        process: require.resolve('process/browser'),
        'process.release': {name: "browser"},
    }),
);
That seems to resolve that, but I get a pretty obscure error:
Copy code
ERROR
specifier.charCodeAt is not a function
ERROR in ./kotlin/secretk-kamel-samples-wasm-js.uninstantiated.mjs
Cannot read properties of undefined (reading 'module')
r
It seems you are trying to use some kind of
process
polyfill for browser?
I think it breaks runtime detection for generated code.
l
I think? One of the js libraries I am trying call throws an error when process isn't defined
It's looking for the presence of an env variable with process
e
This is how that library should do it, in case you want to patch it.
Copy code
const isNodeJs = 
  (typeof process !== 'undefined'
    && process.versions != null
    && process.versions.node != null) ||
  (typeof window !== 'undefined'
    && typeof window.process !== 'undefined'
    && window.process.versions != null
    && window.process.versions.node != null);
l
@Edoardo Luppi I’m pretty sure that code checking for node is generated by kotlin, not whatever library I’m using. So I don’t think I can patch that part
e
Ahh, yeah, noticed now that it's inside one of the three generated files for a WASM module. It's strange then. I'd expect that has been tested quite a lot.
Did the original
process is not defined
come from the same place, or from where?
l
No the original came from the library, but then while adding the plugin fix seems to satisfy the library, it is then causing
process.release
check to fail in the kotlin generated code
e
@Luca ahh, well, you're injecting a fake
process
, so I'd say the problem in the K/JS side is expected. You need to understand why your first dependency wants a process object.
l
yeah, idk. I’m just reimplementing the js lib in kotlin now. Seems easier than dealing with build issues lol
✔️ 1
e
That's what I do 90% of the times.
l
haha yup. thankfully, TS is almost the same as kotlin…. if kotlin were way uglier and a lot worse
My favorite part is when people just randomly leave out TS types and you have to dig through 20 source files to find it. TS is GREAT
e
Yeah I agree. Kotlin needs to grow the library offering, but it will take time. I'll be happy once I'll see a isOdd and isEven libraries on Maven Central
🔥 1
l
lmao
I wish kotlin would make targets opt out of by default, vs opt in
Then amount of time I need to make prs to add targets to libs is annoying