Currently wasm-pack has two common build options:
nodejs produces a commonjs module for node
web produces an es6 module for the web
I'd like to use the same wasm module (published in npm) isomorphically for both nodejs and the web. It almost works - but unfortunately getrandom (run from nodejs) doesn't work at all in an es6 context. It produces this code in a esm file:
imports.wbg.__wbg_modulerequire_0a83c0c31d12d2c7 = function() { return handleError(function (arg0, arg1) {
var ret = module.require(getStringFromWasm0(arg0, arg1));
return addHeapObject(ret);
}, arguments) };
... Which errors, because module is not defined in this context.
I'm not sure how getrandom should work around this. Any thoughts?
Currently wasm-pack has two common build options:
nodejsproduces a commonjs module for nodewebproduces an es6 module for the webI'd like to use the same wasm module (published in npm) isomorphically for both nodejs and the web. It almost works - but unfortunately getrandom (run from nodejs) doesn't work at all in an es6 context. It produces this code in a esm file:
... Which errors, because
moduleis not defined in this context.I'm not sure how getrandom should work around this. Any thoughts?