<p dir="auto"><a href="https://gist.github.com/iugo/1dde0cb200e57f64df71c31ca0400b16">https://gist.github.com/iugo/1dde0cb200e57f64df71c31ca0400b16</a></p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="// main.ts
import { blue } from 'colors';

console.log(blue('hehe'));

// deno compile --output=bin -c deno.json main.ts
// ./bin (error, lost import map)

// deno compile --output=bin --import-map import_map.json main.ts
// ./bin (works!)"><pre class="notranslate"><span class="pl-c">// main.ts</span>
<span class="pl-k">import</span> <span class="pl-kos">{</span> <span class="pl-s1">blue</span> <span class="pl-kos">}</span> <span class="pl-k">from</span> <span class="pl-s">'colors'</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">blue</span><span class="pl-kos">(</span><span class="pl-s">'hehe'</span><span class="pl-kos">)</span><span class="pl-kos">)</span><span class="pl-kos">;</span>

<span class="pl-c">// deno compile --output=bin -c deno.json main.ts</span>
<span class="pl-c">// ./bin (error, lost import map)</span>

<span class="pl-c">// deno compile --output=bin --import-map import_map.json main.ts</span>
<span class="pl-c">// ./bin (works!)</span></pre></div>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="// deno.json
{
  &quot;compilerOptions&quot;: {
    &quot;strict&quot;: true
  },
  &quot;importMap&quot;: &quot;./import_map.json&quot;
}"><pre class="notranslate"><span class="pl-c">// deno.json</span>
<span class="pl-kos">{</span>
  <span class="pl-s">"compilerOptions"</span>: <span class="pl-kos">{</span>
    <span class="pl-s">"strict"</span>: <span class="pl-c1">true</span>
  <span class="pl-kos">}</span><span class="pl-kos">,</span>
  <span class="pl-s">"importMap"</span>: <span class="pl-s">"./import_map.json"</span>
<span class="pl-kos">}</span></pre></div>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="// import_map.json
{
  &quot;imports&quot;: {
    &quot;colors&quot;: &quot;https://deno.land/std@0.167.0/fmt/colors.ts&quot;
  }
}"><pre class="notranslate"><span class="pl-c">// import_map.json</span>
<span class="pl-kos">{</span>
  <span class="pl-s">"imports"</span>: <span class="pl-kos">{</span>
    <span class="pl-s">"colors"</span>: <span class="pl-s">"https://deno.land/std@0.167.0/fmt/colors.ts"</span>
  <span class="pl-kos">}</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto">deno version: 1.28.3</p>
<p dir="auto">Hey! I have a smallish project that I'm working on, and when I compile the command to make a binary, it seems to ignore the <code class="notranslate">import_map.json</code>. I have an <code class="notranslate">"importMap"</code> key in my <code class="notranslate">deno.json</code>, but it doesn't pick it up. When I use <code class="notranslate">--import-map ./import_map.json</code> it works, but it then gives me a warning that the <code class="notranslate">"importMap"</code> key is being ignored. It also works completely fine when I run with <code class="notranslate">deno run</code>, and I don't have to use the <code class="notranslate">--import-map</code> option.</p>
<p dir="auto">Here are the commands I used:</p>
<p dir="auto">Compile: <code class="notranslate">deno compile --allow-env --allow-net --allow-read ./src/main.ts</code><br>
The compilation succeeds, but when I try to run the binary with <code class="notranslate">./main</code> I get this result: <code class="notranslate">error: Relative import path "dotenv/mod.ts" not prefixed with / or ./ or ../ from "file:///home/redxtech/Code/project/src/main.ts"</code></p>
<p dir="auto">Compile with args: <code class="notranslate">deno compile --allow-env --allow-net --allow-read --import-map ./import_map.json ./src/main.ts</code><br>
Warning: <code class="notranslate">Warning the configuration file "file:///home/redxtech/Code/project/deno.json" contains an entry for "importMap" that is being ignored.</code></p>
<p dir="auto">Run: <code class="notranslate">deno run --allow-env --allow-net --allow-read ./src/main.ts</code><br>
Result: works as expected.</p>
<p dir="auto">Output of <code class="notranslate">deno --version</code>:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="deno 1.20.5 (release, x86_64-unknown-linux-gnu)
v8 10.0.139.6
typescript 4.6.2"><pre class="notranslate"><code class="notranslate">deno 1.20.5 (release, x86_64-unknown-linux-gnu)
v8 10.0.139.6
typescript 4.6.2
</code></pre></div>
<p dir="auto">Here's my <code class="notranslate">./deno.json</code> (<code class="notranslate">lint</code> &amp; <code class="notranslate">fmt</code> fields removed):</p>
<div class="highlight highlight-source-json notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="{
  &quot;compilerOptions&quot;: {
    &quot;allowJs&quot;: false,
    &quot;lib&quot;: [&quot;deno.window&quot;, &quot;es2021&quot;],
    &quot;noUnusedLocals&quot;: true,
    &quot;noUnusedParameters&quot;: true,
    &quot;strict&quot;: true
  },
  &quot;importMap&quot;: &quot;./import_map.json&quot;
}"><pre class="notranslate">{
  <span class="pl-ent">"compilerOptions"</span>: {
    <span class="pl-ent">"allowJs"</span>: <span class="pl-c1">false</span>,
    <span class="pl-ent">"lib"</span>: [<span class="pl-s"><span class="pl-pds">"</span>deno.window<span class="pl-pds">"</span></span>, <span class="pl-s"><span class="pl-pds">"</span>es2021<span class="pl-pds">"</span></span>],
    <span class="pl-ent">"noUnusedLocals"</span>: <span class="pl-c1">true</span>,
    <span class="pl-ent">"noUnusedParameters"</span>: <span class="pl-c1">true</span>,
    <span class="pl-ent">"strict"</span>: <span class="pl-c1">true</span>
  },
  <span class="pl-ent">"importMap"</span>: <span class="pl-s"><span class="pl-pds">"</span>./import_map.json<span class="pl-pds">"</span></span>
}</pre></div>
<p dir="auto">and my <code class="notranslate">./import_map.json</code>:</p>
<div class="highlight highlight-source-json notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="{
   &quot;imports&quot;: {
      &quot;dotenv/&quot;: &quot;https://deno.land/x/dotenv@v1.0.1/&quot;,
      &quot;kall/&quot;: &quot;https://denopkg.com/olaven/kall@v1.0.8/&quot;,
      &quot;std/&quot;: &quot;https://deno.land/std@0.133.0/&quot;
   }
}
"><pre class="notranslate">{
   <span class="pl-ent">"imports"</span>: {
      <span class="pl-ent">"dotenv/"</span>: <span class="pl-s"><span class="pl-pds">"</span>https://deno.land/x/dotenv@v1.0.1/<span class="pl-pds">"</span></span>,
      <span class="pl-ent">"kall/"</span>: <span class="pl-s"><span class="pl-pds">"</span>https://denopkg.com/olaven/kall@v1.0.8/<span class="pl-pds">"</span></span>,
      <span class="pl-ent">"std/"</span>: <span class="pl-s"><span class="pl-pds">"</span>https://deno.land/std@0.133.0/<span class="pl-pds">"</span></span>
   }
}
</pre></div>
<p dir="auto">Here's the relevant part of <code class="notranslate">./src/main.ts</code> file where the imports are used:</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import { config as dotEnvConfig } from 'dotenv/mod.ts';"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-kos">{</span> <span class="pl-s1">config</span> <span class="pl-k">as</span> <span class="pl-s1">dotEnvConfig</span> <span class="pl-kos">}</span> <span class="pl-k">from</span> <span class="pl-s">'dotenv/mod.ts'</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">If you need any more info I would be happy to provide it.</p>