<p dir="auto">Both me and another discord user both get<br>
<code class="notranslate">Failed to request to tsserver Error: Debug Failure. False expression: Containing file should be a module.</code><br>
when trying to use workers.<br>
This seems to happen when running <a href="https://deno.land/manual/runtime/workers" rel="nofollow">the manual example</a><br>
but also in other cases. (see the code after the error stacktrace)</p>
<p dir="auto">This is my stacktrace of the error. I assume it is the same for them</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Starting Deno language server...
  version: 1.12.2 (release, x86_64-unknown-linux-gnu)
  executable: /home/skyler/.deno/bin/deno
Connected to &quot;Visual Studio Code&quot; 1.58.2
language server initialized
Enabling import suggestions for: https://deno.land
Enabling import suggestions for: https://crux.land
Server ready.
Failed to request to tsserver Error: Debug Failure. False expression: Containing file should be a module.
    at checkImportMetaProperty (deno:cli/tsc/00_typescript.js:72534:22)
    at checkMetaProperty (deno:cli/tsc/00_typescript.js:72509:24)
    at checkExpressionWorker (deno:cli/tsc/00_typescript.js:74908:28)
    at checkExpression (deno:cli/tsc/00_typescript.js:74799:38)
    at checkNonNullExpression (deno:cli/tsc/00_typescript.js:69770:37)
    at checkPropertyAccessExpression (deno:cli/tsc/00_typescript.js:69815:85)
    at checkExpressionWorker (deno:cli/tsc/00_typescript.js:74879:28)
    at checkExpression (deno:cli/tsc/00_typescript.js:74799:38)
    at checkExpressionWithContextualType (deno:cli/tsc/00_typescript.js:74446:28)
    at getSignatureApplicabilityError (deno:cli/tsc/00_typescript.js:70940:35)
[Error - 11:20:27 AM] Request textDocument/semanticTokens/full failed.
  Message: Invalid request
  Code: -32600"><pre class="notranslate"><code class="notranslate">Starting Deno language server...
  version: 1.12.2 (release, x86_64-unknown-linux-gnu)
  executable: /home/skyler/.deno/bin/deno
Connected to "Visual Studio Code" 1.58.2
language server initialized
Enabling import suggestions for: https://deno.land
Enabling import suggestions for: https://crux.land
Server ready.
Failed to request to tsserver Error: Debug Failure. False expression: Containing file should be a module.
    at checkImportMetaProperty (deno:cli/tsc/00_typescript.js:72534:22)
    at checkMetaProperty (deno:cli/tsc/00_typescript.js:72509:24)
    at checkExpressionWorker (deno:cli/tsc/00_typescript.js:74908:28)
    at checkExpression (deno:cli/tsc/00_typescript.js:74799:38)
    at checkNonNullExpression (deno:cli/tsc/00_typescript.js:69770:37)
    at checkPropertyAccessExpression (deno:cli/tsc/00_typescript.js:69815:85)
    at checkExpressionWorker (deno:cli/tsc/00_typescript.js:74879:28)
    at checkExpression (deno:cli/tsc/00_typescript.js:74799:38)
    at checkExpressionWithContextualType (deno:cli/tsc/00_typescript.js:74446:28)
    at getSignatureApplicabilityError (deno:cli/tsc/00_typescript.js:70940:35)
[Error - 11:20:27 AM] Request textDocument/semanticTokens/full failed.
  Message: Invalid request
  Code: -32600
</code></pre></div>
<p dir="auto">worker.js</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="const globalCache = new Map();
onmessage = messageHandler;

function set(cacheName, key, value) {
const cache = globalCache.get(cacheName);
if (!cache) globalCache.set(cacheName, new Map()); 
globalCache.get(cacheName).set(key, value);
}

function get(cacheName, key) {
return globalCache.get(cacheName)?.get(key);
}

function deleteKey(cacheName, key) {
return globalCache.get(cacheName)?.delete(key);
}

function deleteCache(cacheName) {
return globalCache.delete(cacheName);
}

function messageHandler(message, sab) {
const data = message.data;
switch (data.cmd) {
  case &quot;set&quot;:
    set(data.args[0], data.args[1], data.args[2]);
    break;
  case &quot;get&quot;:
    get(data.args[0], data.args[1]);
    break;
  case &quot;delete&quot;:
    deleteKey(data.args[0], data.args[1]);
    break;
  case &quot;delete_cache&quot;:
    deleteCache(data.args);
    break;
}
postMessage(data.id);
}"><pre class="notranslate"><span class="pl-k">const</span> <span class="pl-s1">globalCache</span> <span class="pl-c1">=</span> <span class="pl-k">new</span> <span class="pl-v">Map</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-s1">onmessage</span> <span class="pl-c1">=</span> <span class="pl-s1">messageHandler</span><span class="pl-kos">;</span>

<span class="pl-k">function</span> <span class="pl-en">set</span><span class="pl-kos">(</span><span class="pl-s1">cacheName</span><span class="pl-kos">,</span> <span class="pl-s1">key</span><span class="pl-kos">,</span> <span class="pl-s1">value</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
<span class="pl-k">const</span> <span class="pl-s1">cache</span> <span class="pl-c1">=</span> <span class="pl-s1">globalCache</span><span class="pl-kos">.</span><span class="pl-en">get</span><span class="pl-kos">(</span><span class="pl-s1">cacheName</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-c1">!</span><span class="pl-s1">cache</span><span class="pl-kos">)</span> <span class="pl-s1">globalCache</span><span class="pl-kos">.</span><span class="pl-en">set</span><span class="pl-kos">(</span><span class="pl-s1">cacheName</span><span class="pl-kos">,</span> <span class="pl-k">new</span> <span class="pl-v">Map</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">globalCache</span><span class="pl-kos">.</span><span class="pl-en">get</span><span class="pl-kos">(</span><span class="pl-s1">cacheName</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-en">set</span><span class="pl-kos">(</span><span class="pl-s1">key</span><span class="pl-kos">,</span> <span class="pl-s1">value</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span>

<span class="pl-k">function</span> <span class="pl-en">get</span><span class="pl-kos">(</span><span class="pl-s1">cacheName</span><span class="pl-kos">,</span> <span class="pl-s1">key</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
<span class="pl-k">return</span> <span class="pl-s1">globalCache</span><span class="pl-kos">.</span><span class="pl-en">get</span><span class="pl-kos">(</span><span class="pl-s1">cacheName</span><span class="pl-kos">)</span><span class="pl-kos">?.</span><span class="pl-en">get</span><span class="pl-kos">(</span><span class="pl-s1">key</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span>

<span class="pl-k">function</span> <span class="pl-en">deleteKey</span><span class="pl-kos">(</span><span class="pl-s1">cacheName</span><span class="pl-kos">,</span> <span class="pl-s1">key</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
<span class="pl-k">return</span> <span class="pl-s1">globalCache</span><span class="pl-kos">.</span><span class="pl-en">get</span><span class="pl-kos">(</span><span class="pl-s1">cacheName</span><span class="pl-kos">)</span><span class="pl-kos">?.</span><span class="pl-en">delete</span><span class="pl-kos">(</span><span class="pl-s1">key</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span>

<span class="pl-k">function</span> <span class="pl-en">deleteCache</span><span class="pl-kos">(</span><span class="pl-s1">cacheName</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
<span class="pl-k">return</span> <span class="pl-s1">globalCache</span><span class="pl-kos">.</span><span class="pl-en">delete</span><span class="pl-kos">(</span><span class="pl-s1">cacheName</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span>

<span class="pl-k">function</span> <span class="pl-en">messageHandler</span><span class="pl-kos">(</span><span class="pl-s1">message</span><span class="pl-kos">,</span> <span class="pl-s1">sab</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
<span class="pl-k">const</span> <span class="pl-s1">data</span> <span class="pl-c1">=</span> <span class="pl-s1">message</span><span class="pl-kos">.</span><span class="pl-c1">data</span><span class="pl-kos">;</span>
<span class="pl-k">switch</span> <span class="pl-kos">(</span><span class="pl-s1">data</span><span class="pl-kos">.</span><span class="pl-c1">cmd</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
  <span class="pl-k">case</span> <span class="pl-s">"set"</span>:
    <span class="pl-en">set</span><span class="pl-kos">(</span><span class="pl-s1">data</span><span class="pl-kos">.</span><span class="pl-c1">args</span><span class="pl-kos">[</span><span class="pl-c1">0</span><span class="pl-kos">]</span><span class="pl-kos">,</span> <span class="pl-s1">data</span><span class="pl-kos">.</span><span class="pl-c1">args</span><span class="pl-kos">[</span><span class="pl-c1">1</span><span class="pl-kos">]</span><span class="pl-kos">,</span> <span class="pl-s1">data</span><span class="pl-kos">.</span><span class="pl-c1">args</span><span class="pl-kos">[</span><span class="pl-c1">2</span><span class="pl-kos">]</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-k">break</span><span class="pl-kos">;</span>
  <span class="pl-k">case</span> <span class="pl-s">"get"</span>:
    <span class="pl-en">get</span><span class="pl-kos">(</span><span class="pl-s1">data</span><span class="pl-kos">.</span><span class="pl-c1">args</span><span class="pl-kos">[</span><span class="pl-c1">0</span><span class="pl-kos">]</span><span class="pl-kos">,</span> <span class="pl-s1">data</span><span class="pl-kos">.</span><span class="pl-c1">args</span><span class="pl-kos">[</span><span class="pl-c1">1</span><span class="pl-kos">]</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-k">break</span><span class="pl-kos">;</span>
  <span class="pl-k">case</span> <span class="pl-s">"delete"</span>:
    <span class="pl-en">deleteKey</span><span class="pl-kos">(</span><span class="pl-s1">data</span><span class="pl-kos">.</span><span class="pl-c1">args</span><span class="pl-kos">[</span><span class="pl-c1">0</span><span class="pl-kos">]</span><span class="pl-kos">,</span> <span class="pl-s1">data</span><span class="pl-kos">.</span><span class="pl-c1">args</span><span class="pl-kos">[</span><span class="pl-c1">1</span><span class="pl-kos">]</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-k">break</span><span class="pl-kos">;</span>
  <span class="pl-k">case</span> <span class="pl-s">"delete_cache"</span>:
    <span class="pl-en">deleteCache</span><span class="pl-kos">(</span><span class="pl-s1">data</span><span class="pl-kos">.</span><span class="pl-c1">args</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-k">break</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span>
<span class="pl-en">postMessage</span><span class="pl-kos">(</span><span class="pl-s1">data</span><span class="pl-kos">.</span><span class="pl-c1">id</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto">mod.ts</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="interface Message {
  cmd: &quot;set&quot; | &quot;get&quot; | &quot;delete&quot; | &quot;delete_cache&quot;;
  id: number;
  args: [string, string, unknown] | [string, string] | string;
}

const worker = new Worker(new URL(&quot;./worker.js&quot;, import.meta.url), {type: &quot;module&quot;});

function set() {}"><pre class="notranslate"><span class="pl-k">interface</span> <span class="pl-smi">Message</span> <span class="pl-kos">{</span>
  <span class="pl-c1">cmd</span>: <span class="pl-s">"set"</span> <span class="pl-c1">|</span> <span class="pl-s">"get"</span> <span class="pl-c1">|</span> <span class="pl-s">"delete"</span> <span class="pl-c1">|</span> <span class="pl-s">"delete_cache"</span><span class="pl-kos">;</span>
  <span class="pl-c1">id</span>: <span class="pl-smi">number</span><span class="pl-kos">;</span>
  <span class="pl-c1">args</span>: <span class="pl-kos">[</span><span class="pl-smi">string</span><span class="pl-kos">,</span> <span class="pl-smi">string</span><span class="pl-kos">,</span> <span class="pl-smi">unknown</span><span class="pl-kos">]</span> <span class="pl-c1">|</span> <span class="pl-kos">[</span><span class="pl-smi">string</span><span class="pl-kos">,</span> <span class="pl-smi">string</span><span class="pl-kos">]</span> <span class="pl-c1">|</span> <span class="pl-smi">string</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span>

<span class="pl-k">const</span> <span class="pl-s1">worker</span> <span class="pl-c1">=</span> <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">"./worker.js"</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-kos">{</span><span class="pl-c1">type</span>: <span class="pl-s">"module"</span><span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">;</span>

<span class="pl-k">function</span> <span class="pl-en">set</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span><span class="pl-kos">}</span></pre></div>
<p dir="auto">Thought this was already fixed in <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="775746263" data-permission-text="Title is private" data-url="https://github.com/denoland/deno/issues/8914" data-hovercard-type="pull_request" data-hovercard-url="/denoland/deno/pull/8914/hovercard" href="https://github.com/denoland/deno/pull/8914">#8914</a>?</p>
<p dir="auto">Using latest deno canary and actual vscode-deno.</p>
<p dir="auto">Adding a <code class="notranslate">export {}</code> to the file helps.</p>
<h3 dir="auto">Actual Result</h3>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Starting Deno language server...
  version: 1.8.0+04740af (release, x86_64-unknown-linux-gnu)
Connected to &quot;Visual Studio Code&quot; 1.53.1
language server initialized
Server ready.
ERROR TSLS = Error: Debug Failure. False expression: Containing file should be a module.
    at checkImportMetaProperty (deno:cli/tsc/00_typescript.js:70604:22)
    at checkMetaProperty (deno:cli/tsc/00_typescript.js:70579:24)
    at checkExpressionWorker (deno:cli/tsc/00_typescript.js:72940:28)
    at checkExpression (deno:cli/tsc/00_typescript.js:72831:38)
    at checkNonNullExpression (deno:cli/tsc/00_typescript.js:67851:37)
    at checkPropertyAccessExpression (deno:cli/tsc/00_typescript.js:67896:85)
    at checkExpressionWorker (deno:cli/tsc/00_typescript.js:72911:28)
    at checkExpression (deno:cli/tsc/00_typescript.js:72831:38)
    at checkExpressionWithContextualType (deno:cli/tsc/00_typescript.js:72478:28)
    at getSignatureApplicabilityError (deno:cli/tsc/00_typescript.js:69000:35)
ERROR TSLS = Error: Debug Failure. False expression: Containing file should be a module.
    at checkImportMetaProperty (deno:cli/tsc/00_typescript.js:70604:22)
    at checkMetaProperty (deno:cli/tsc/00_typescript.js:70579:24)
    at checkExpressionWorker (deno:cli/tsc/00_typescript.js:72940:28)
    at checkExpression (deno:cli/tsc/00_typescript.js:72831:38)
    at checkNonNullExpression (deno:cli/tsc/00_typescript.js:67851:37)
    at checkPropertyAccessExpression (deno:cli/tsc/00_typescript.js:67896:85)
    at checkExpressionWorker (deno:cli/tsc/00_typescript.js:72911:28)
    at checkExpression (deno:cli/tsc/00_typescript.js:72831:38)
    at checkExpressionWithContextualType (deno:cli/tsc/00_typescript.js:72478:28)
    at getSignatureApplicabilityError (deno:cli/tsc/00_typescript.js:69000:35)
ERROR TSLS = Error: Debug Failure. False expression: Containing file should be a module.
    at checkImportMetaProperty (deno:cli/tsc/00_typescript.js:70604:22)
    at checkMetaProperty (deno:cli/tsc/00_typescript.js:70579:24)
    at checkExpressionWorker (deno:cli/tsc/00_typescript.js:72940:28)
    at checkExpression (deno:cli/tsc/00_typescript.js:72831:38)
    at checkNonNullExpression (deno:cli/tsc/00_typescript.js:67851:37)
    at checkPropertyAccessExpression (deno:cli/tsc/00_typescript.js:67896:85)
    at checkExpressionWorker (deno:cli/tsc/00_typescript.js:72911:28)
    at checkExpression (deno:cli/tsc/00_typescript.js:72831:38)
    at checkExpressionWithContextualType (deno:cli/tsc/00_typescript.js:72478:28)
    at getSignatureApplicabilityError (deno:cli/tsc/00_typescript.js:69000:35)
"><pre class="notranslate"><code class="notranslate">Starting Deno language server...
  version: 1.8.0+04740af (release, x86_64-unknown-linux-gnu)
Connected to "Visual Studio Code" 1.53.1
language server initialized
Server ready.
ERROR TSLS = Error: Debug Failure. False expression: Containing file should be a module.
    at checkImportMetaProperty (deno:cli/tsc/00_typescript.js:70604:22)
    at checkMetaProperty (deno:cli/tsc/00_typescript.js:70579:24)
    at checkExpressionWorker (deno:cli/tsc/00_typescript.js:72940:28)
    at checkExpression (deno:cli/tsc/00_typescript.js:72831:38)
    at checkNonNullExpression (deno:cli/tsc/00_typescript.js:67851:37)
    at checkPropertyAccessExpression (deno:cli/tsc/00_typescript.js:67896:85)
    at checkExpressionWorker (deno:cli/tsc/00_typescript.js:72911:28)
    at checkExpression (deno:cli/tsc/00_typescript.js:72831:38)
    at checkExpressionWithContextualType (deno:cli/tsc/00_typescript.js:72478:28)
    at getSignatureApplicabilityError (deno:cli/tsc/00_typescript.js:69000:35)
ERROR TSLS = Error: Debug Failure. False expression: Containing file should be a module.
    at checkImportMetaProperty (deno:cli/tsc/00_typescript.js:70604:22)
    at checkMetaProperty (deno:cli/tsc/00_typescript.js:70579:24)
    at checkExpressionWorker (deno:cli/tsc/00_typescript.js:72940:28)
    at checkExpression (deno:cli/tsc/00_typescript.js:72831:38)
    at checkNonNullExpression (deno:cli/tsc/00_typescript.js:67851:37)
    at checkPropertyAccessExpression (deno:cli/tsc/00_typescript.js:67896:85)
    at checkExpressionWorker (deno:cli/tsc/00_typescript.js:72911:28)
    at checkExpression (deno:cli/tsc/00_typescript.js:72831:38)
    at checkExpressionWithContextualType (deno:cli/tsc/00_typescript.js:72478:28)
    at getSignatureApplicabilityError (deno:cli/tsc/00_typescript.js:69000:35)
ERROR TSLS = Error: Debug Failure. False expression: Containing file should be a module.
    at checkImportMetaProperty (deno:cli/tsc/00_typescript.js:70604:22)
    at checkMetaProperty (deno:cli/tsc/00_typescript.js:70579:24)
    at checkExpressionWorker (deno:cli/tsc/00_typescript.js:72940:28)
    at checkExpression (deno:cli/tsc/00_typescript.js:72831:38)
    at checkNonNullExpression (deno:cli/tsc/00_typescript.js:67851:37)
    at checkPropertyAccessExpression (deno:cli/tsc/00_typescript.js:67896:85)
    at checkExpressionWorker (deno:cli/tsc/00_typescript.js:72911:28)
    at checkExpression (deno:cli/tsc/00_typescript.js:72831:38)
    at checkExpressionWithContextualType (deno:cli/tsc/00_typescript.js:72478:28)
    at getSignatureApplicabilityError (deno:cli/tsc/00_typescript.js:69000:35)

</code></pre></div>
<h3 dir="auto">Expected Result</h3>
<p dir="auto">File will be formatted.</p>