<p dir="auto">Attempting to load any ts file into a worker where an import map is used fails within the worker. It results in a relative import path error.</p>
<p dir="auto">We extensively use import maps in our project to keep it clean and prevent having a lot of relative paths "../../../" in our imports.</p>
<h2 dir="auto">Steps to reproduce</h2>
<ol dir="auto">
<li>Create the following files under the same directory:</li>
</ol>
<p dir="auto"><strong>import_map.json</strong></p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="{
   &quot;imports&quot;: {
      &quot;fmt/&quot;: &quot;https://deno.land/std@0.55.0/fmt/&quot;
   }
}"><pre class="notranslate"><span class="pl-kos">{</span>
   <span class="pl-s">"imports"</span>: <span class="pl-kos">{</span>
      <span class="pl-s">"fmt/"</span>: <span class="pl-s">"https://deno.land/std@0.55.0/fmt/"</span>
   <span class="pl-kos">}</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto"><strong>color.ts</strong></p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import { red } from &quot;fmt/colors.ts&quot;;

console.log(red(&quot;hello world&quot;));"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-kos">{</span> <span class="pl-s1">red</span> <span class="pl-kos">}</span> <span class="pl-k">from</span> <span class="pl-s">"fmt/colors.ts"</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-en">red</span><span class="pl-kos">(</span><span class="pl-s">"hello world"</span><span class="pl-kos">)</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<p dir="auto"><strong>main.ts</strong></p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="new Worker(new URL('./color.ts', import.meta.url).href, {type: 'module'})"><pre class="notranslate"><span class="pl-k">new</span> <span class="pl-smi">Worker</span><span class="pl-kos">(</span><span class="pl-k">new</span> <span class="pl-smi">URL</span><span class="pl-kos">(</span><span class="pl-s">'./color.ts'</span><span class="pl-kos">,</span> <span class="pl-k">import</span><span class="pl-kos">.</span><span class="pl-c1">meta</span><span class="pl-kos">.</span><span class="pl-c1">url</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-c1">href</span><span class="pl-kos">,</span> <span class="pl-kos">{</span><span class="pl-c1">type</span>: <span class="pl-s">'module'</span><span class="pl-kos">}</span><span class="pl-kos">)</span></pre></div>
<ol start="2" dir="auto">
<li>Run this command:</li>
</ol>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="deno run --allow-read --importmap=import_map.json --unstable main.ts"><pre class="notranslate"><code class="notranslate">deno run --allow-read --importmap=import_map.json --unstable main.ts
</code></pre></div>
<h2 dir="auto">Expected output</h2>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="hello world"><pre class="notranslate"><code class="notranslate">hello world
</code></pre></div>
<h2 dir="auto">Actual output</h2>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="error: Uncaught Error: relative import path &quot;fmt/colors.ts&quot; not prefixed with / or ./ or ../ Imported from &quot;file:///color.ts&quot;"><pre class="notranslate"><code class="notranslate">error: Uncaught Error: relative import path "fmt/colors.ts" not prefixed with / or ./ or ../ Imported from "file:///color.ts"
</code></pre></div>
<h2 dir="auto">Environment</h2>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="deno 1.1.3"><pre class="notranslate"><code class="notranslate">deno 1.1.3
</code></pre></div>