<p dir="auto">Deno doesn't support <code class="notranslate">require</code> but there is one thing where <code class="notranslate">require</code> wins against ES6 imports:</p>
<p dir="auto">In Node.js we can do</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="delete require.cache[require.resolve(somePath)];"><pre class="notranslate"><span class="pl-k">delete</span> <span class="pl-en">require</span><span class="pl-kos">.</span><span class="pl-c1">cache</span><span class="pl-kos">[</span><span class="pl-en">require</span><span class="pl-kos">.</span><span class="pl-en">resolve</span><span class="pl-kos">(</span><span class="pl-s1">somePath</span><span class="pl-kos">)</span><span class="pl-kos">]</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">and delete required file from cache to load it again after it get changed in runtime. With imports we can't do like this. Even if we use dymanic imports (<code class="notranslate">await import("./module.ts")</code>) twice, we both times get the module Deno loaded first time.</p>
<p dir="auto">There is a workaround about it. We can add a query parameter to file path like this:</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="mod = await import(`./mod.ts?foo=${anyRandomlyGeneratedString}`);"><pre class="notranslate"><span class="pl-s1">mod</span> <span class="pl-c1">=</span> <span class="pl-k">await</span> <span class="pl-k">import</span><span class="pl-kos">(</span><span class="pl-s">`./mod.ts?foo=<span class="pl-s1"><span class="pl-kos">${</span><span class="pl-s1">anyRandomlyGeneratedString</span><span class="pl-kos">}</span></span>`</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">and it will be loaded again and we get a new its version. But the problem is that BOTH versions of this module will exist in the cache, I suppose. That's not cool.</p>
<p dir="auto">Why do we even have to store dynamically imported modules in cache? Maybe better make them uncached and garbage-collected and make it possible to import the same module multiple times and each time get the current module content without any ugly workarounds? Otherwise it looks like dynamic imports are just called dynamic but still work in a static way.</p>
<p dir="auto">I'm writing code using dynamic module import for dynamically generated code (tool like node-dev). In Deno, once module imported dynamically, they will be never updated while process running. Are there some way to invalidate module cache? In node.js, required module can be deleted.</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="Deno.writeTextFileSync(&quot;./target.ts&quot;, &quot;export const value = 1;&quot;);
const v1 = await import(&quot;./target.ts&quot;)
console.log(v1.value); // 1
Deno.writeTextFileSync(&quot;./target.ts&quot;, &quot;export const values = 2&quot;);
const v2 = await import(&quot;./target.ts&quot;)
console.log(v2.value); // should be 2 but got 1"><pre class="notranslate"><span class="pl-smi">Deno</span><span class="pl-kos">.</span><span class="pl-en">writeTextFileSync</span><span class="pl-kos">(</span><span class="pl-s">"./target.ts"</span><span class="pl-kos">,</span> <span class="pl-s">"export const value = 1;"</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-k">const</span> <span class="pl-s1">v1</span> <span class="pl-c1">=</span> <span class="pl-k">await</span> <span class="pl-k">import</span><span class="pl-kos">(</span><span class="pl-s">"./target.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-s1">v1</span><span class="pl-kos">.</span><span class="pl-c1">value</span><span class="pl-kos">)</span><span class="pl-kos">;</span> <span class="pl-c">// 1</span>
<span class="pl-smi">Deno</span><span class="pl-kos">.</span><span class="pl-en">writeTextFileSync</span><span class="pl-kos">(</span><span class="pl-s">"./target.ts"</span><span class="pl-kos">,</span> <span class="pl-s">"export const values = 2"</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-k">const</span> <span class="pl-s1">v2</span> <span class="pl-c1">=</span> <span class="pl-k">await</span> <span class="pl-k">import</span><span class="pl-kos">(</span><span class="pl-s">"./target.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-s1">v2</span><span class="pl-kos">.</span><span class="pl-c1">value</span><span class="pl-kos">)</span><span class="pl-kos">;</span> <span class="pl-c">// should be 2 but got 1</span></pre></div>