I get a Uncaught (in promise) TypeError: second argument must be an object error when I run the following code:
async function loadWasm(url) {
const fetchPromise = fetch(url)
const { module, instance } = await WebAssembly.instantiateStreaming(fetchPromise)
// [...]
}
loadWasm('http://localhost:3000/path/to/file.wasm')
Looking at the documentation, it says that the second argument of WebAssembly.instantiateStreaming (importObject) is optional, so I don't understand why the browser makes it mandatory nonetheless?
I've tested this in Firefox 78.7.0esr (64-bit) and Chrome 88.0.4324.96 (Official Build) (64-bit). In case it's of any importance, the code is transpiled with webpack 5 in a ruby on rails 6.1 application.
Update:
I opened an issue on mdn's github repository thinking the documentation might need an update. So far it seems the documentation is good so it might be an implementation issue. To be confirmed.
Update:
It's neither an implementation issue nor a documentation mistake. I posted my conclusion about this issue in the answer below.