<p dir="auto">Running the folloing code:<br>
<code class="notranslate">console.log(  (import.meta as ImportMeta).url)</code><br>
or<br>
<code class="notranslate">console.log(  import.meta.url)</code></p>
<p dir="auto">using:</p>
<p dir="auto"><code class="notranslate">deno run -c .\tsconfig.json .\meta.ts </code></p>
<p dir="auto">with <a href="https://github.com/Bidek56/deno-py-websocket/blob/master/client/tsconfig.json">tsconfig.json</a></p>
<p dir="auto">results in:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="error: TS2339 [ERROR]: Property 'url' does not exist on type 'ImportMeta'.
console.log(  (import.meta as ImportMeta).url)
"><pre class="notranslate"><code class="notranslate">error: TS2339 [ERROR]: Property 'url' does not exist on type 'ImportMeta'.
console.log(  (import.meta as ImportMeta).url)

</code></pre></div>
<p dir="auto">but in globals.ts <strong>ImportMeta</strong> has url. Any help appreaciated. Thx</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="  interface ImportMeta {
    url: string;
    main: boolean;
  }"><pre class="notranslate"><code class="notranslate">  interface ImportMeta {
    url: string;
    main: boolean;
  }
</code></pre></div>
<p dir="auto">The deno process keeps running (does not exit) using the WebSockets API on the client side.</p>
<p dir="auto">On the backend side I use the <code class="notranslate">ws</code> server example from the <code class="notranslate">std</code> module: <a href="https://github.com/denoland/deno/tree/master/std/ws">https://github.com/denoland/deno/tree/master/std/ws</a> readme.</p>
<p dir="auto">On the client side (running with deno) I use the following code. The deno process doesn't finish although the <code class="notranslate">ws</code> connection is closed (the server confirms this):</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="async function connect(url: string): Promise&lt;WebSocket&gt; {
  return new Promise((resolve, reject) =&gt; {
    const socket = new WebSocket(url);
    socket.onopen = () =&gt; resolve(socket);
    socket.onerror = (err) =&gt; reject(err);
  });
}

async function getMessage(socket: WebSocket) {
  return new Promise((resolve, reject) =&gt; {
    socket.onmessage = (event: any) =&gt; {
      resolve(event.data);
    };
    socket.onclose = () =&gt; resolve(&quot;connection is closed&quot;);
  });
}

const socket = await connect(&quot;ws://0.0.0.0:8080&quot;);
socket.send(&quot;Here's some text that the server is urgently awaiting!&quot;);
const message = await getMessage(socket);
console.log(message);
socket.close();"><pre class="notranslate"><span class="pl-k">async</span> <span class="pl-k">function</span> <span class="pl-en">connect</span><span class="pl-kos">(</span><span class="pl-s1">url</span>: <span class="pl-smi">string</span><span class="pl-kos">)</span>: <span class="pl-smi">Promise</span><span class="pl-kos">&lt;</span><span class="pl-smi">WebSocket</span><span class="pl-kos">&gt;</span> <span class="pl-kos">{</span>
  <span class="pl-k">return</span> <span class="pl-k">new</span> <span class="pl-smi">Promise</span><span class="pl-kos">(</span><span class="pl-kos">(</span><span class="pl-s1">resolve</span><span class="pl-kos">,</span> <span class="pl-s1">reject</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span>
    <span class="pl-k">const</span> <span class="pl-s1">socket</span> <span class="pl-c1">=</span> <span class="pl-k">new</span> <span class="pl-smi">WebSocket</span><span class="pl-kos">(</span><span class="pl-s1">url</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-s1">socket</span><span class="pl-kos">.</span><span class="pl-en">onopen</span> <span class="pl-c1">=</span> <span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-en">resolve</span><span class="pl-kos">(</span><span class="pl-s1">socket</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-s1">socket</span><span class="pl-kos">.</span><span class="pl-en">onerror</span> <span class="pl-c1">=</span> <span class="pl-kos">(</span><span class="pl-s1">err</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-en">reject</span><span class="pl-kos">(</span><span class="pl-s1">err</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
  <span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span>

<span class="pl-k">async</span> <span class="pl-k">function</span> <span class="pl-en">getMessage</span><span class="pl-kos">(</span><span class="pl-s1">socket</span>: <span class="pl-smi">WebSocket</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
  <span class="pl-k">return</span> <span class="pl-k">new</span> <span class="pl-smi">Promise</span><span class="pl-kos">(</span><span class="pl-kos">(</span><span class="pl-s1">resolve</span><span class="pl-kos">,</span> <span class="pl-s1">reject</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span>
    <span class="pl-s1">socket</span><span class="pl-kos">.</span><span class="pl-en">onmessage</span> <span class="pl-c1">=</span> <span class="pl-kos">(</span><span class="pl-s1">event</span>: <span class="pl-smi">any</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span>
      <span class="pl-en">resolve</span><span class="pl-kos">(</span><span class="pl-s1">event</span><span class="pl-kos">.</span><span class="pl-c1">data</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">socket</span><span class="pl-kos">.</span><span class="pl-en">onclose</span> <span class="pl-c1">=</span> <span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-en">resolve</span><span class="pl-kos">(</span><span class="pl-s">"connection is closed"</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
  <span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span>

<span class="pl-k">const</span> <span class="pl-s1">socket</span> <span class="pl-c1">=</span> <span class="pl-k">await</span> <span class="pl-en">connect</span><span class="pl-kos">(</span><span class="pl-s">"ws://0.0.0.0:8080"</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-s1">socket</span><span class="pl-kos">.</span><span class="pl-en">send</span><span class="pl-kos">(</span><span class="pl-s">"Here's some text that the server is urgently awaiting!"</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-k">const</span> <span class="pl-s1">message</span> <span class="pl-c1">=</span> <span class="pl-k">await</span> <span class="pl-en">getMessage</span><span class="pl-kos">(</span><span class="pl-s1">socket</span><span class="pl-kos">)</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">message</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-s1">socket</span><span class="pl-kos">.</span><span class="pl-en">close</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>