<p dir="auto">In Deno WebAssembly modules can be imported directly. However, there seems to be a bug where if a big file is being downloaded via the network, this fails.</p>
<h2 dir="auto">How to reproduce</h2>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="// This fails
import * as sqlite from &quot;https://deno.land/x/sqlite/build/sqlite.wasm&quot;;"><pre class="notranslate"><span class="pl-c">// This fails</span>
<span class="pl-k">import</span> <span class="pl-c1">*</span> <span class="pl-k">as</span> <span class="pl-s1">sqlite</span> <span class="pl-k">from</span> <span class="pl-s">"https://deno.land/x/sqlite/build/sqlite.wasm"</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">Download the big WASM file: <code class="notranslate">git clone https://github.com/dyedgreen/deno-sqlite &amp;&amp; cd deno-sqlite</code>.</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="// This works
import * as sqlite from &quot;./build/sqlite.wasm&quot;;"><pre class="notranslate"><span class="pl-c">// This works</span>
<span class="pl-k">import</span> <span class="pl-c1">*</span> <span class="pl-k">as</span> <span class="pl-s1">sqlite</span> <span class="pl-k">from</span> <span class="pl-s">"./build/sqlite.wasm"</span><span class="pl-kos">;</span></pre></div>
<h2 dir="auto">Error</h2>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$ deno file.js
Compile https://deno.land/x/sqlite/mod.ts
error: Uncaught CompileError: WebAssembly.compile(): expected 7299055 bytes, fell off end @+13
► $deno$/compiler.ts:710:40
    at window_ts_10.window.onmessage ($deno$/compiler.ts:710:40)
    at workerMain ($deno$/workers.ts:93:51)"><pre class="notranslate"><code class="notranslate">$ deno file.js
Compile https://deno.land/x/sqlite/mod.ts
error: Uncaught CompileError: WebAssembly.compile(): expected 7299055 bytes, fell off end @+13
► $deno$/compiler.ts:710:40
    at window_ts_10.window.onmessage ($deno$/compiler.ts:710:40)
    at workerMain ($deno$/workers.ts:93:51)
</code></pre></div>
<p dir="auto">There seems to be an issue where Deno does not exit correctly if an uncaught exception occurs and a big WASM module was imported.</p>
<p dir="auto">This seems to happen for modules around <code class="notranslate">100K</code> and bigger (from testing on my machine, vary the <code class="notranslate">10000</code> in for loop to get different size binary).</p>
<p dir="auto">Note: I ran across the issue while working on: <a href="https://github.com/dyedgreen/deno-sqlite">https://github.com/dyedgreen/deno-sqlite</a>, which uses a binary of around 1MB.</p>
<h2 dir="auto">Steps to reproduce:</h2>
<ol dir="auto">
<li>Build big WASM file:</li>
</ol>
<div class="highlight highlight-source-shell notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="deno --allow-write gen_big.js
clang --target=wasm32 --no-standard-libraries -Wl,--no-entry -nostartfiles -O0 -o big.wasm big.c"><pre class="notranslate">deno --allow-write gen_big.js
clang --target=wasm32 --no-standard-libraries -Wl,--no-entry -nostartfiles -O0 -o big.wasm big.c</pre></div>
<ol start="2" dir="auto">
<li>Run <code class="notranslate">deno big.js</code></li>
</ol>
<h3 dir="auto">Needed files</h3>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="// gen_big.js

const prefix = &quot;test&quot;;
const str = &quot;int ?(a, b) { return a+b; }&quot;;

const lines = [];
const main = [&quot;int a = 0;&quot;];
for (let i = 0; i &lt; 10000; i ++) {
  lines.push(str.replace(&quot;?&quot;, prefix.concat(i)));
  main.push(&quot;a = &quot; + prefix.concat(i) + &quot;(a, b);&quot;);
  if (i % 1000 === 0)
    console.log(i);
}
main.push(&quot;return a;&quot;);
const total = lines.join(&quot;\n&quot;) + &quot;\n\n&quot; + `int __attribute__((used)) __attribute__ ((visibility (&quot;default&quot;))) add(int b) {\n${main.join(&quot;\n&quot;)}\n};\n`;
await Deno.writeFile(&quot;big.c&quot;, new TextEncoder().encode(total));"><pre class="notranslate"><span class="pl-c">// gen_big.js</span>

<span class="pl-k">const</span> <span class="pl-s1">prefix</span> <span class="pl-c1">=</span> <span class="pl-s">"test"</span><span class="pl-kos">;</span>
<span class="pl-k">const</span> <span class="pl-s1">str</span> <span class="pl-c1">=</span> <span class="pl-s">"int ?(a, b) { return a+b; }"</span><span class="pl-kos">;</span>

<span class="pl-k">const</span> <span class="pl-s1">lines</span> <span class="pl-c1">=</span> <span class="pl-kos">[</span><span class="pl-kos">]</span><span class="pl-kos">;</span>
<span class="pl-k">const</span> <span class="pl-s1">main</span> <span class="pl-c1">=</span> <span class="pl-kos">[</span><span class="pl-s">"int a = 0;"</span><span class="pl-kos">]</span><span class="pl-kos">;</span>
<span class="pl-k">for</span> <span class="pl-kos">(</span><span class="pl-k">let</span> <span class="pl-s1">i</span> <span class="pl-c1">=</span> <span class="pl-c1">0</span><span class="pl-kos">;</span> <span class="pl-s1">i</span> <span class="pl-c1">&lt;</span> <span class="pl-c1">10000</span><span class="pl-kos">;</span> <span class="pl-s1">i</span> <span class="pl-c1">++</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
  <span class="pl-s1">lines</span><span class="pl-kos">.</span><span class="pl-en">push</span><span class="pl-kos">(</span><span class="pl-s1">str</span><span class="pl-kos">.</span><span class="pl-en">replace</span><span class="pl-kos">(</span><span class="pl-s">"?"</span><span class="pl-kos">,</span> <span class="pl-s1">prefix</span><span class="pl-kos">.</span><span class="pl-en">concat</span><span class="pl-kos">(</span><span class="pl-s1">i</span><span class="pl-kos">)</span><span class="pl-kos">)</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
  <span class="pl-s1">main</span><span class="pl-kos">.</span><span class="pl-en">push</span><span class="pl-kos">(</span><span class="pl-s">"a = "</span> <span class="pl-c1">+</span> <span class="pl-s1">prefix</span><span class="pl-kos">.</span><span class="pl-en">concat</span><span class="pl-kos">(</span><span class="pl-s1">i</span><span class="pl-kos">)</span> <span class="pl-c1">+</span> <span class="pl-s">"(a, b);"</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
  <span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-s1">i</span> <span class="pl-c1">%</span> <span class="pl-c1">1000</span> <span class="pl-c1">===</span> <span class="pl-c1">0</span><span class="pl-kos">)</span>
    <span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-s1">i</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span>
<span class="pl-s1">main</span><span class="pl-kos">.</span><span class="pl-en">push</span><span class="pl-kos">(</span><span class="pl-s">"return a;"</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-k">const</span> <span class="pl-s1">total</span> <span class="pl-c1">=</span> <span class="pl-s1">lines</span><span class="pl-kos">.</span><span class="pl-en">join</span><span class="pl-kos">(</span><span class="pl-s">"\n"</span><span class="pl-kos">)</span> <span class="pl-c1">+</span> <span class="pl-s">"\n\n"</span> <span class="pl-c1">+</span> <span class="pl-s">`int __attribute__((used)) __attribute__ ((visibility ("default"))) add(int b) {\n<span class="pl-s1"><span class="pl-kos">${</span><span class="pl-s1">main</span><span class="pl-kos">.</span><span class="pl-en">join</span><span class="pl-kos">(</span><span class="pl-s">"\n"</span><span class="pl-kos">)</span><span class="pl-kos">}</span></span>\n};\n`</span><span class="pl-kos">;</span>
<span class="pl-k">await</span> <span class="pl-v">Deno</span><span class="pl-kos">.</span><span class="pl-en">writeFile</span><span class="pl-kos">(</span><span class="pl-s">"big.c"</span><span class="pl-kos">,</span> <span class="pl-k">new</span> <span class="pl-v">TextEncoder</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-en">encode</span><span class="pl-kos">(</span><span class="pl-s1">total</span><span class="pl-kos">)</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="// big.js

import * as mod from &quot;./big.wasm&quot;;

throw new Error(&quot;Does not die :(&quot;);"><pre class="notranslate"><span class="pl-c">// big.js</span>

<span class="pl-k">import</span> <span class="pl-c1">*</span> <span class="pl-k">as</span> <span class="pl-s1">mod</span> <span class="pl-k">from</span> <span class="pl-s">"./big.wasm"</span><span class="pl-kos">;</span>

<span class="pl-k">throw</span> <span class="pl-k">new</span> <span class="pl-v">Error</span><span class="pl-kos">(</span><span class="pl-s">"Does not die :("</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>