title: Module not found: Error: Can't resolve 'fs' - Electron
body: <p>I am working on a PDF viewer, basically, it's a <a href="https://github.com/mozilla/pdf.js" rel="nofollow noreferrer">mozilla pdf.js project</a>. I cloned the repo and installed the dependencies and everything works fine, even when I try to build the project through <code>gulp generic</code>, it works without any issue.</p>
  <p>The problem started when I have installed <code>electron</code>, to create a desktop version of the viewer, everything still worked even in the electron app, but I have used <code>const { ipcRenderer } = require('electron')</code> to send messages to the main process, from the browser window. It works fine as well until I try to build the app using <code>gulp generic</code>, it throughs an error that says <code>Module not found: Error: Can't resolve 'fs' in '/*******/pdf.js/node_modules/electron'</code>. When I remove the <code>require('electron')</code> from the script it builds correctly.</p>
  <p><strong>My Code</strong></p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function webViewerLoad() {
    const isElectron =
      navigator.userAgent.toLowerCase().indexOf(" electron/") &gt; -1;
    if (isElectron) {
      const { ipcRenderer } = require("electron");
      ipcRenderer.send("electron:reload", v);
    }
  }
  
  
    document.addEventListener("DOMContentLoaded", webViewerLoad, true);</code></pre>
  </div>
  </div>
  </p>
  <p><strong>The Error</strong></p>
  <p><a href="https://i.stack.imgur.com/lhYja.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lhYja.png" alt="enter image description here" /></a></p>