title: Electron: Uncaught Error: Cannot find module
body: <p>I'm building my first electron desktop app and I'm getting a <em>&quot;cannot find module&quot;</em> error when I use <code>require()</code> in one file to import the other. <strong>Both files are in the same folder and there's no misspelling.</strong>.</p>
  <p>Here's the main file <code>index.js</code></p>
  <pre><code>const app = require('electron')
  const store = require('./datacontainer') //Here I import the other file
  
  if(store.users.length==0) { // throws exception: store is not defined
      ...
  }
  </code></pre>
  <p>and below is the imported file <code>datacontainer.js</code></p>
  <pre><code>var exp = module.exports = {};
  
  exp.users = [{user1},{user2},...];
  
  ...
  </code></pre>
  <p>However, when I run the app and look at the console, it throws the following exeption;</p>
  <pre><code>Uncaught Error: Cannot find module './datacontainer'
      at Module._resolveFilename (module.js:543)
      at Function.Module._resolveFilename (C:\mm_apps\report-viewer\node_modules\electron\dist\resources\electron.asar\common\reset-search-paths.js:35)
      at Function.Module._load (module.js:473)
      at Module.require (module.js:586)
      at require (internal/module.js:11)
      at index.js:10
  </code></pre>
  <p>What am I doing wrong or missing?</p>
  <h1>UPDATES:</h1>
  <p>In the <code>index.html</code> where the <code>index.js</code> is used, the error goes away if I reference the script like the following</p>
  <pre><code>&lt;script&gt;
     require('./scripts/index')
  &lt;/script&gt;
  </code></pre>
  <p>but throws above error when referenced this way</p>
  <pre><code>&lt;script src=&quot;./scripts/index.js&quot;&gt;&lt;/script&gt;
  </code></pre>
  <p>what gives?</p>