Javascript 如何在React Native中加载.wasm文件?

Javascript 如何在React Native中加载.wasm文件?,javascript,react-native,webassembly,Javascript,React Native,Webassembly,我一直尝试在EngestPrimeApp.E/P>中加载一个WebBaseMuleCube(.WASM)文件生成的C++代码,编译为WebasMalk-。 这是我获取.wasm文件的代码: import fs from 'react-native-fs'; if (!global.WebAssembly) { global.WebAssembly = require('webassemblyjs'); } const fetchWasm = async () => { cons

我一直尝试在EngestPrimeApp.E/P>中加载一个WebBaseMuleCube(.WASM)文件生成的C++代码,编译为WebasMalk-。 这是我获取.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
};
从“react native fs”导入fs;
如果(!global.WebAssembly){
global.WebAssembly=require('webassemblyjs');
}
const fetchWasm=async()=>{
const wasm=wait fetch(`${fs.MainBundlePath}/calculator.wasm`);
console.log(wasm);
//返回:响应{type:“default”,状态:200,确定:true,状态文本:未定义,标题:标题,…}
const mod=wait WebAssembly.instantiateStreaming(wasm);
控制台日志(mod);
//抛出:TypeError:未能对“WebAssembly”执行“compile”:必须提供一个参数,该参数必须是响应或承诺对象
};
我在谷歌搜索结果中尝试了所有我能找到的东西,但到目前为止没有任何效果。不幸的是,最相关的问题没有得到回答


有人知道我做错了什么吗?任何帮助都将不胜感激

我假设React native JS runtime JSC在Android构建中仍然不支持WebAssembly 这个问题仍然悬而未决
https://github.com/react-native-community/jsc-android-buildscripts/issues/113

另一种方法是使用Webview,但我认为这不是您所期望的。

根据WebAssembly.instantiateStreaming,返回承诺。为了检索它的输出,我认为您需要添加一个
。然后()
我使用wait来获取承诺的结果,并将其分配给'mod'变量。尝试:
const mod=wait WebAssembly.instancestreaming(wasm)。然后(mod=>console.log(mod))只是一个猜测,因为我想我以前也遇到过类似的问题。我认为您的
wasm
变量不是实际的对象,否则
console.log
不会在开头追加“Response”。您可能需要使用
JSON.parse(wasm)
。您是否成功地实现了这一点?