title: How to instantiate an es6 class that has been transpiled to es5
body: <p>I am creating a module that I want to publish to NPM. The module exports a class that should be instantiated using the new keyword. I want that the package should be importable using the es5 require keyword as well es6 import keyword. I had transpiled the code to es5 for backward compatibility. When I test it out with es6 import and transpile es5, the code run as expected. However, when I test it out using the require() keyword, I get an error that the class is not a constructor. I have created sample codes to replicate the problem.</p>
  
  <p>This is a sample class which I transpiled to es5 in the file index2.js</p>
  
  <pre><code>// classe.js
  
  class MyClass {
    constructor() {
      this.name = 'name'
    }
    greet() {
      return `Hello ${this.name}`;
    }
  }
  
  export default MyClass;
  
  </code></pre>
  
  <h1>To test the code I created the two tests codes below</h1>
  
  <p>Here is the es5 implementation. I expect that since index2 is already in es5 it should run by executing <code>node test1</code></p>
  
  <pre><code>// test1.js
  
  const MyClass = require('./index2');
  
  console.log(MyClass)
  
  const greeter = new MyClass()
  const greeting = greeter.greet();
  console.log(greeting)
  
  </code></pre>
  
  <p>Here the es6 implementation. When I transpile this and execute as <code>node test2</code>, it produces the expected result.</p>
  
  <pre><code>// test2.js
  
  import MyClass from './index2';
  
  console.log(MyClass)
  
  const greeter = new MyClass()
  const greeting = greeter.greet();
  console.log(greeting)
  
  </code></pre>
  
  <h1>Here is my expected result</h1>
  
  <pre><code>[Function: MyClass]
  Hello name 
  </code></pre>
  
  <h1>this is the error I am getting when I run the test1.js</h1>
  
  <pre><code>{ default: [Function: MyClass] }
  /Users/godfreytutu/Desktop/classe/test1.js:5
  const greeter = new MyClass()
                  ^
  
  TypeError: MyClass is not a constructor
  
  </code></pre>
  
  <p>Please, how should I implement it so that I can use the require keyword as well as the import keyword? Thanks.</p>