wasm-tool/rollup-plugin-rust

inlineWasm true still contains reference to .wasm file

matthme opened this issue · 5 comments

The javascript bundled with inlineWasm: true still contains a reference to a wasm file like so:

async function init(input) {
    if (typeof input === 'undefined') {
        input = new URL('index_bg.wasm', import.meta.url);
    }

[...]

Is this intended? It seems like a bug to me and leads to rollup errors when trying to bundle apps that depend on a module packaged that way:

[!] (plugin rollup-plugin-import-meta-assets) Error: ENOENT: no such file or directory, open 'path/to/module/bundled/with/rollup-plugin-rust/node_modules/[module name]/dist/index_bg.wasm'

The app that depends on such a module bundles fine if I remove this if statement containing the reference to the not used .wasm file.

Pauan commented

This is caused by wasm-bindgen, so I'm not sure if there's anything I can do about it.

Maybe I could hijack import.meta.url?

Okay. I'd have to look more into the code to judge on that or to see other ways to fix it. But it would definitely be nice if it was fixed because it causes troubles for users of our package generated with the plugin.

Pauan commented

This ended up being easier to fix than I thought, since wasm-bindgen has an --omit-default-module-path option.

I published version 2.3.3, let me know if it fixes the problem for you.

That's awesome, many thanks for fixing it so quickly! It does resolve the problem indeed.

ku1ik commented

Thank you for this fix. Up until now I used this workaround: asciinema/asciinema-player@e8217ef

Now I don't need it, awesome.