title: Accessing non-existent property of module.exports inside circular dependency NodeJS
body: <p>Im having some issues when using module.exports inside NodeJS, and I've followed multiple guides, and im almost certain Im doing it right.
  I have to scripts, main.js and event.js. Im trying to share a function from main.js to event.js, but its not working. Here is the code:</p>
  <p>Main.js</p>
  <pre><code>function Scan(){
      if(fs.readdirSync('./events/').length === 0){
          console.log(colors.yellow('Events Folder Empty, Skipping Scan'))
      } else {
          var events = fs.readdirSync('./events/').filter(file =&gt; file.endsWith('.json'))
                  for(const file of events){
                      let rawdata = fs.readFileSync('./events/' + file);
                      let cJSON = JSON.parse(rawdata);
                  }
                  events.sort()
                  tevent = events[0]
                  StartAlerter()
                  }
  }
  
  module.exports = { Scan };
  </code></pre>
  <p>Event.js</p>
  <pre><code>const main = require('../main')
  
  main.Scan;
  </code></pre>
  <p>This returns the error:</p>
  <pre><code>(node:19292) Warning: Accessing non-existent property 'Scan' of module exports inside circular dependency
  (Use `node --trace-warnings ...` to show where the warning was created)
  </code></pre>
  <p>What am I doing wrong?</p>