簡體   English   中英

如何在 nodejs 14.15 中運行 WebAssembly

[英]How can I run WebAssembly in nodejs 14.15

我從其官方網站下載 nodejs 14.15.0 ,然后運行以下命令

# ./bin/node --expose-wasm  
Welcome to Node.js v14.15.0.
Type ".help" for more information.
> Wasm
Uncaught ReferenceError: Wasm is not defined

我想也許Wasm不可用,所以我需要使用WebAssembly

所以我運行以下代碼

const fs = require('fs');
const buf = fs.readFileSync('./addTwo.wasm');

function toUint8Array(buf) {
  var u = new Uint8Array(buf.length);
  for (var i = 0; i < buf.length; ++i) {
    u[i] = buf[i];
  }
  return u;
}

const lib = WebAssembly.instantiateModule(toUint8Array(buf)).exports;

但是它輸出

TypeError: WebAssembly.instantiateModule is not a function

WebAssembly.instantiateModule不是WebAssembly上的 function object https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly#

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM