title: WebPack 5 with Web worker using React/Typescript
body: <p>How do i make web worker work with create-react-app, Typescript and Webpack 5 work? The documentation is very limited and I can't find any good explanation. I do not want to use webpack-loader etc.</p>
  <p>I am instantiating the worker using webpack 5 suggested API. I have got it working with ComLink but it uses RPC which i do not want (further ComLink cannot copy either socket or rxjs observables data structures).</p>
  <p>I want to create web worker so i could stream data over websockets, any pointers are much appreciated.</p>
  <pre><code> const worker = new Worker(new URL('./test.worker.ts', import.meta.url));
   worker.postMessage(&quot;test&quot;);
  </code></pre>
  <p>But it throws below exception.</p>
  <blockquote>
  <p>Module parse failed: Unexpected token (16:64) File was processed with
  these loaders:  *
  ./node_modules/@pmmmwh/react-refresh-webpack-plugin/loader/index.js  *
  ./node_modules/babel-loader/lib/index.js You may need an additional
  loader to handle the result of these loaders. |  |<br />
  React.useEffect(() =&gt; {</p>
  <blockquote>
  <pre><code>const worker = new Worker(new URL('./test.worker.ts', import.meta.url)); |     worker.postMessage(&quot;test&quot;); |   }, []);
  </code></pre>
  </blockquote>
  </blockquote>