首页 > 解决方案 > [TypeError: WebAssembly.instantiate(): Imports 参数必须存在并且必须是一个对象]

问题描述

我正在尝试将 golang WebAssembly 组件导入 NodeJS,但一直遇到这个问题:

[TypeError: WebAssembly.instantiate(): Imports argument must be present and must be an object]

我认为问题是我需要找到一种方法来包含它,wasm_exec.js因为它可以在 Chrome 中使用。

这是我测试过的:

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

async function asyncCall() {

    try {
        //listing messages in users mailbox 
          const lib = await WebAssembly.instantiate(new Uint8Array(buf)).then(res => res.instance.exports);

        } catch (err) {
          console.log(err)
        }

    console.log(res);
    // expected output: 'resolved'
  }

  asyncCall();

标签: node.jsgowebassembly

解决方案


推荐阅读