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
You're exporting Track
as default, so you should use default import. Change
import { Track } from './track';
to
import Track from './track';
See What is "export default" in javascript?
When you do import { Track } from './track'
you're trying to access the Track
property of the exported object (which is the Track class), which is undefined (so it's not a constructor).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With