title: Cannot require node_modules in electron worker process
body: <h2>Question</h2>
  
  <p>I'm trying to use web workers in electron. So far I'm able to instanciate the worker process from the renderer process, but when I try to do a <code>require('some_module')</code> in the worker process the process crashes with the error.</p>
  
  <blockquote>
    <p><em>Cannot find module 'some_module'</em>. </p>
  </blockquote>
  
  <p>The cjs loader cannot find my module apparently. But when I make the same <code>require</code> call from the renderer process, I'm able to <code>require</code> the module.</p>
  
  <p>I've followed all the steps mentioned <a href="https://electronjs.org/docs/tutorial/multithreading" rel="nofollow noreferrer">here</a>. Also I've set the option<code>nodeIntegrationInWorker: true</code> and I can make <code>require</code> calls to node inbuilt modules like <code>fs</code> with no problems.</p>
  
  <hr>
  
  <h2>A few observations</h2>
  
  <ol>
  <li><p><code>__dirname</code> in the rendered process resolves to </p>
  
  <blockquote>
    <p><em>root/node_modules/electron/dist/resources/electron.asar/renderer</em></p>
  </blockquote>
  
  <p>and in the worker process resolves to </p>
  
  <blockquote>
    <p><em>root/node_modules/electron/dist/resources/electron.asar/worker</em></p>
  </blockquote>
  
  <p>as far as I've done the reading the require function should be able to find my module in the <strong>node_modules</strong> dir which is parent to both the <strong>renderer</strong> and <strong>worker</strong> dir</p></li>
  <li><p>A quick look at the <code>process</code> global in the worker reveals that <code>process.type</code> is equals <code>worker</code> while <code>process.argv[1]</code> is equals <code>--type=renderer</code> which I find strange. </p></li>
  </ol>
  
  <hr>
  
  <p><strong><em>Meta</em>:</strong>
  Electron version = "4.0.0", platform = "win32", arch = "x64", node version = "v10.11.0"</p>
  
  <p>Any help in this regard would be appreciated.</p>