title: How to import a node module inside an angular web worker?
body: <p><strong>I try to import a node module inside an <a href="https://angular.io/guide/web-worker" rel="noreferrer">Angular 8 web worker</a>, but get an compile error 'Cannot find module'. Anyone know how to solve this?</strong></p>
  
  <p>I created a new worker inside my electron project with <code>ng generate web-worker app</code>, like described in the above mentioned ng documentation. </p>
  
  <p>All works fine until i add some import like <code>path</code> or <code>fs-extra</code> e.g.:</p>
  
  <pre><code>/// &lt;reference lib="webworker" /&gt;    
  import * as path from 'path';
  
  addEventListener('message', ({ data }) =&gt; {    
    console.log(path.resolve('/'))
    const response = `worker response to ${data}`;
    postMessage(response);
  });
  </code></pre>
  
  <p>This import works fine in any other ts component but inside the web worker i get a compile <strong>error</strong> with this message e.g.</p>
  
  <pre><code>Error: app/app.worker.ts:3:23 - error TS2307: Cannot find module 'path'.
  </code></pre>
  
  <p>How can i fix this? Maybe i need some additional parameter in the generated <code>tsconfig.worker.json</code>?</p>
  
  <p>To <strong>reproduce</strong> the error, run:</p>
  
  <pre><code>$ git clone https://github.com/hoefling/stackoverflow-57774039
  $ cd stackoverflow-57774039
  $ yarn build
  </code></pre>
  
  <p>Or check out the project's <a href="https://travis-ci.org/hoefling/stackoverflow-57774039/jobs/581774748#L247" rel="noreferrer">build log</a> on Travis.</p>
  
  <p>Note:</p>
  
  <p>1) I only found <a href="https://stackoverflow.com/questions/56616120/how-to-import-a-typescript-module-inside-a-web-worker-in-angular-8">this</a> as a similar problem, but the answer handles only custom modules.</p>
  
  <p>2) I tested the same import with a <a href="https://github.com/trusktr/electron-web-worker-example" rel="noreferrer">minimal electron seed</a> which uses web workers and it worked, but this example uses plain java script without angular.</p>