Search code examples
javascriptecmascript-6webpacktranspiler

Type Error - Is Not a Constructor


Wanted to instantiate a module within ES6 javascript and transpile to ES5. I am setting up a new class in my project which is es6 / webpack. I have 2 files: track.js which has the following --

export default class Track {
  constructor() {
    this.o = {};
  }
}

The other is index.js --

import { Track } from './track';

const track = new Track();
console.log(track);

I am trying to have console log show an empty object. Instead, I am getting -- Uncaught TypeError: _track.Track is not a constructor


Solution

  • The problem is with the way you're importing Track in index.js. You need to either import like this:

    import Track from './track';
    

    Or in track.js you need to export it like this:

    export {Track}