title: WebAssembly LinkError: function import requires a callable
body: <p>I've recently started working with WebAssembly. I hit a problem trying to use log in my C code. I recreated the error in the simplest way I could. The error I get is</p>
  
  <pre><code>Uncaught (in promise) LinkError: WebAssembly.Instance(): Import #1 module="env" function="_log" error: function import requires a callable
  </code></pre>
  
  <p>The error points to this function, specifically <code>WebAsembly.Instance(module, imports)</code></p>
  
  <pre><code>function loadWebAssembly(filename, imports = {}) {
    return fetch(filename)
      .then((response) =&gt; response.arrayBuffer())
      .then((buffer) =&gt; WebAssembly.compile(buffer))
      .then((module) =&gt; {
        imports.env = imports.env || {}
        Object.assign(imports.env, {
          memoryBase: 0,
          tableBase: 0,
          memory: new WebAssembly.Memory({
            initial: 256,
            maximum: 512,
          }),
          table: new WebAssembly.Table({
            initial: 0,
            maximum: 0,
            element: 'anyfunc',
          }),
        })
        return new WebAssembly.Instance(module, imports)
      })
  }
  </code></pre>
  
  <p>(I call this function with <code>loadWebAssembly('/test.wasm')</code>)</p>
  
  <p>My C code is</p>
  
  <pre><code>#include &lt;math.h&gt;
  
  double test(v) {
    return log(v)
  }
  </code></pre>
  
  <p>and gets no errors when compiled with</p>
  
  <pre><code>emcc test.c -Os -s WASM=1 -s SIDE_MODULE=1 -o test.wasm
  </code></pre>
  
  <p>I haven't been able to fix this error, I hope someone can help me out.</p>