Uncaught (in promise) LinkError: WebAssembly Instantiation: Import #1 module="env" function="__memory_base" error: global import must be a number

Uncaught (in promise) LinkError: WebAssembly Instantiation: Import #1 module="env" function="__memory_base" error: global import must be a number

我正在关注 Google CodeLab An Introduction to Web Assembly 来学习 WebAssembly。

当我处理 Serve over HTTP 的步骤时,我遇到了以下错误:

Uncaught (in promise) LinkError: WebAssembly Instantiation: Import #1 module="env" function="__memory_base" error: global import must be a number or WebAssembly.Global object
    at createWebAssembly (http://127.0.0.1:8000/:11:57)
    at async init (http://127.0.0.1:8000/:46:18)

网页上的JavaScript运行:

  async function createWebAssembly(path, importObject) {
    const result = await window.fetch(path);
    const bytes = await result.arrayBuffer();
    return WebAssembly.instantiate(bytes, importObject);
  }

  const memory = new WebAssembly.Memory({initial: 256, maximum: 256});
  let exports = null;

  async function init() {
    const env = {
      'abortWhosebug': _ => { throw new Error('overflow'); },
      'table': new WebAssembly.Table({initial: 0, maximum: 0, element: 'anyfunc'}),
      'tableBase': 0,
      'memory': memory,
      'memoryBase': 1024,
      'STACKTOP': 0,
      'STACK_MAX': memory.buffer.byteLength,
    };
    const importObject = {env};

    const wasm = await createWebAssembly('output.wasm', importObject);
    exports = wasm.instance.exports;
    console.info('got exports', exports);
    exports._board_init();  // setup lyff board

    // TODO: interact with lyff board
  }
  init();

错误来自WebAssembly.instantiate(bytes, importObject);但是,我无法进入该功能。有人可以让我知道我错过了什么吗?提前致谢!

我遇到了同样的问题,并在 GitHub 上找到了解决方案:

https://github.com/googlecodelabs/web-assembly-introduction/issues/11

With later version of emcc replace memoryBase with __memory_base and tableBase with __table_base.