title: Javascript ES6 on Nodejs : TypeError: object is not a constructor
body: <p>I have this sample class <strong>sync.js</strong> as a module somewhere on my project. </p>
  
  <pre><code>'use strict';
  
  export default class Sync{
  
      constructor(dbConnection){
          this.dbConnection = dbConnection;
      }
  
      test(){
          return "This is a test " + this.dbConnection;
      }
  }
  </code></pre>
  
  <p>Then somewhere on my controller I am using this class as : </p>
  
  <pre><code>'use strict';
  
  import Sync from '../../path/to/module'; // &lt;-- works fine
  
  const sync = new Sync('CONNECTION!'); // &lt;-- meh
  
  console.log(sync.test());
  </code></pre>
  
  <p>I was expecting something like this to be logged on the console <code>This is a test CONNECTION!</code>. But instead I am getting this error. <code>TypeError: object is not a constructor</code></p>
  
  <p>What did I do wrong?</p>
  
  <p>By the way if I removed the line <code>const sync = new Sync('CONNECTION!');</code> and changed <code>console.log()</code> to <code>console.log(Sync.test());</code> the output <code>This is a test undefined</code> is printed which is kind of what I expected. But what's wrong with my instatiation?</p>
  
  <p><strong>WTF?</strong></p>
  
  <p><strong>Edit</strong></p>
  
  <p>Guys I think I found the problem, based on <a href="https://stackoverflow.com/users/1945651/jlrishe">@JLRishe</a> and <a href="https://stackoverflow.com/users/3928341/nem035">rem035</a> pointed out, it was returning the instance of the class not the class itself. In fact there is an <code>index.js</code> that imports the <code>'./sync'</code> js file and exporting is as <code>export default new Sync();</code>. Here's the whole <code>index.js</code>. </p>
  
  <pre><code>'use strict';
  
  import Sync from './sync';
  
  export default new Sync(); // &lt;-- potential prodigal code
  </code></pre>
  
  <p>The module tree looks like this. </p>
  
  <pre><code>module
    |
    |_ lib
    |  |_ index.js // this is the index.js I am talking about
    |  |_ sync.js
    |
    |_ index.js // the entry point, contains just `module.exports = require('./lib');`
  </code></pre>
  
  <p>Now. How do I export <code>export default new Sync();</code> without doing <code>new</code>?</p>