When building a wasmJs app with `wasmJsBrowserProd...
# webassembly
r
When building a wasmJs app with
wasmJsBrowserProductionWebpack
task, the created js file contains some code with full paths of my linux machine:
Copy code
[...] {l=(await import("node:module")).default.createRequire("file://
/home/rjaros/git/kilua/build/js/packages/kilua-examples-hello-world-wasm-js/kotlin/kilua-examples-hello-world-wasm-js.uninstantiated.mjs");const e=l("fs"),t=l("path"),r=l("u
rl").fileURLToPath("file:///home/rjaros/git/kilua/build/js/packages/kilua-examples-hello-world-wasm-js/kotlin/kilua-examples-hello-world-wasm-js.uninstantiated.mjs"),o=t.dir
name(r),n=e.readFileSync(t.resolve(o,c)),s=new WebAssembly.Module(n); [...]
Seems to me like a small privacy exposure which doesn't seem to be required for anything (the app works fine when published from a web server without this path/file).
a
@Ilya Goncharov [JB] what can we use it for?
i
Hm, thanks, it is interesting, it is because we add all kinds of wasm loading into mjs file even if some of them are unnecessary (in your example, it is loading in nodejs, but you are in browser environment). cc @Svyatoslav Kuzmich [JB]
s
It looks like this is how webpack transpiles
import.meta.url
, used for relative path resolution in Node.js. Ilya, do you think we can stop it, maybe by avoiding transpiling ES modules?
i
Yes, it is because
import.meta.url
indeed. There is option in webpack to disable evaluation of it. We can use it in Gradle plugin, but now you can add it to webpack configuration locally https://webpack.js.org/configuration/module/#moduleparserjavascriptimportmeta
r
I've tried adding this to my `webpack.config.d/webpack.js`:
Copy code
config.module.parser = {
    javascript: {
        importMeta: false,
    },
};
The resulting js doesn't contain the path anymore, but it DOES NOT work. I see this in the browser console:
Copy code
Uncaught SyntaxError: import.meta may only appear in a module
i
Okay, looks like I need to investigate. Seems browser fails to even parse such expression even if it will not be executed
🙏 1
r
@Ilya Goncharov [JB] Is there any YT issue for this? It's still like this in 2.0.0-RC1 - the bundle file still references local files and is unusable in Node.js when the files are not available. I'm currently using this primitive Regexp filtering in a gradle plugin to workaround: https://github.com/rjaros/kilua/blob/main/plugins/kilua-gradle-plugin/src/main/kotlin/dev/kilua/gradle/KiluaPlugin.kt#L240-L247
i
Hi, I checked a few ways to get rid of such problem. And the best option in short-term from my point of view is to use
import.meta.resolve
(https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import.meta/resolve) Webpack does not transform it into local file paths
r
Can this help me somehow to fix the issue on 2.0.0-RC1?
i
I don’t think that this information can help as is, it is for information
r
Is there an issue I can follow?