wasmer-js icon indicating copy to clipboard operation
wasmer-js copied to clipboard

How to use wasmer-js in the browser?

Open vedantroy opened this issue 5 years ago • 3 comments

I'm trying to create a bundle for running wasmer-js in the browser. However, I keep on running into issues. Specifically, the browser bindings seem to import a buffer/crypto polyfill. However, this buffer polyfill is not installed as a dependency, so my script crashes in the browser.

How do we build a Javascript file that uses wasmer-js, with the necessary dependencies attached, that will run in the browser?

I am using rollup. I've tried several different methods, but I keep on running into undefined variables and other such things.

Specifically, I get the issue:

Missing global variable names
Use output.globals to specify browser global variable names corresponding to external modules
crypto (guessing 'crypto')
buffer (guessing 'buffer$1')

Reproduction repo: https://github.com/vedantroy/wasmer-js-reproduction

vedantroy avatar Jun 11 '20 05:06 vedantroy

It seems there is an issue in the rollup bundler. Crypto and buffer should be automatically added by rollup to the bundle, but they aren't.

syrusakbary avatar Jun 16 '20 21:06 syrusakbary

You might need https://github.com/calvinmetcalf/rollup-plugin-node-builtins

mischnic avatar Jun 16 '20 22:06 mischnic

Did you solve this in the meantime @vedantroy ?

ChristianWeyer avatar Aug 04 '20 16:08 ChristianWeyer

This is no longer an issue in Wasmer's new JavaScript SDK, @wasmer/sdk.

Michael-F-Bryan avatar Dec 13 '23 08:12 Michael-F-Bryan