我一直在尝试加载一个 WebAssembly (.wasm) 文件——生成的 C++ 代码由 Emscripten 编译为 WebAssembly——在 React-Native 应用程序中。
这是我获取 .wasm 文件的代码:
import fs from 'react-native-fs';
if (!global.WebAssembly) {
global.WebAssembly = require('webassemblyjs');
}
const fetchWasm = async () => {
const wasm = await fetch(`${fs.MainBundlePath}/calculator.wasm`);
console.log(wasm);
// Returns: Response {type: "default", status: 200, ok: true, statusText: undefined, headers: Headers, …}
const mod = await WebAssembly.instantiateStreaming(wasm);
console.log(mod);
// Throws: TypeError: Failed to execute 'compile' on 'WebAssembly': An argument must be provided, which must be a Response or Promise<Response> object …
Run Code Online (Sandbox Code Playgroud)