<p dir="auto">I have been working on Deno compatibility for the TypeScript data validation library "Zod" (<a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="765128918" data-permission-text="Title is private" data-url="https://github.com/colinhacks/zod/issues/269" data-hovercard-type="pull_request" data-hovercard-url="/colinhacks/zod/pull/269/hovercard" href="https://github.com/colinhacks/zod/pull/269">colinhacks/zod#269</a>). The <code class="notranslate">v3</code> development branch is working properly under <code class="notranslate">deno run</code>, but I am still encountering some errors in the output of <code class="notranslate">deno bundle</code>.</p>
<p dir="auto">I am testing with the latest canary build representing the current <code class="notranslate">master</code>, 36ff7bd (<code class="notranslate">deno 1.6.3+36ff7bd (canary, x86_64-unknown-linux-gnu)</code>).  <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="783302645" data-permission-text="Title is private" data-url="https://github.com/denoland/deno/issues/9085" data-hovercard-type="pull_request" data-hovercard-url="/denoland/deno/pull/9085/hovercard" href="https://github.com/denoland/deno/pull/9085">#9085</a>/<a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="778794394" data-permission-text="Title is private" data-url="https://github.com/swc-project/swc/issues/1318" data-hovercard-type="pull_request" data-hovercard-url="/swc-project/swc/pull/1318/hovercard" href="https://github.com/swc-project/swc/pull/1318">swc-project/swc#1318</a> resolved the error I was previously encountering in <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="783302645" data-permission-text="Title is private" data-url="https://github.com/denoland/deno/issues/9085" data-hovercard-type="pull_request" data-hovercard-url="/denoland/deno/pull/9085/hovercard" href="https://github.com/denoland/deno/pull/9085">#9085</a>, but I am encountering new ones.</p>
<p dir="auto">when I run <code class="notranslate">deno bundle https://raw.githubusercontent.com/colinhacks/zod/654680afc2ede388e71e09104eac5a0088fe3207/deno/lib/index.ts &amp;&amp; deno run bundle.js</code>, an error is thrown while evaluating the bundled module:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="error: Uncaught ReferenceError: util is not defined
const ZodIssueCode = util.arrayToEnum([
                     ^
    at file:///mnt/c/Users/_/src/bundle.js:1:22"><pre class="notranslate"><code class="notranslate">error: Uncaught ReferenceError: util is not defined
const ZodIssueCode = util.arrayToEnum([
                     ^
    at file:///mnt/c/Users/_/src/bundle.js:1:22
</code></pre></div>
<p dir="auto">When we look at the bundle output, we can indeed see that the contents of the <code class="notranslate">"./helpers/util.ts";</code> import are not present in the bundled output.</p>
<p dir="auto">When we don't go through the bundler, but instead just use <code class="notranslate">deno run https://raw.githubusercontent.com/colinhacks/zod/654680afc2ede388e71e09104eac5a0088fe3207/deno/lib/index.ts</code> directly, the library is imported and evaluated without any errors.</p>
<p dir="auto">I experienced the same result (<code class="notranslate">run</code> successful, <code class="notranslate">bundle</code>-and-<code class="notranslate">run</code> missing modules) when I tried bundling a real project of mine that was using Zod and Deno, instead of the above example.</p>
<p dir="auto">deno@v1.5.4</p>
<p dir="auto"><em>mod.ts</em></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="export namespace Bar {
  export function foo() {
    console.log(&quot;foo&quot;);
  }
}"><pre class="notranslate"><code class="notranslate">export namespace Bar {
  export function foo() {
    console.log("foo");
  }
}
</code></pre></div>
<p dir="auto"><em>main.ts</em></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="import { Bar } from &quot;./mod.ts&quot;;
Bar.foo();"><pre class="notranslate"><code class="notranslate">import { Bar } from "./mod.ts";
Bar.foo();
</code></pre></div>
<div class="highlight highlight-source-shell notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="deno bundle main.ts main.bundle.js"><pre class="notranslate">deno bundle main.ts main.bundle.js</pre></div>
<p dir="auto">but <em>main.bundle.js</em>:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Bar.foo();"><pre class="notranslate"><code class="notranslate">Bar.foo();
</code></pre></div>
<div class="highlight highlight-source-shell notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="deno run main.bundle.js"><pre class="notranslate">deno run main.bundle.js</pre></div>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="error: Uncaught ReferenceError: Bar is not defined
Bar.foo();
....."><pre class="notranslate"><code class="notranslate">error: Uncaught ReferenceError: Bar is not defined
Bar.foo();
.....
</code></pre></div>