ES6 modules and inheritance

Viewed 4602

I have the following JavaScript files:

src/js/classes/Lexus.js:

import {Car} from 'src/js/classes/Car';

export class Lexus extends Car {
  constructor() {
    super("Lexus");
  }
}

src/js/classes/Mercedes.js:

import {Car} from 'src/js/classes/Car';

export class Mercedes extends Car {
  constructor() {
    super("Mercedes");
  }
}

src/js/classes/Car.js:

import {Lexus} from 'src/js/classes/Lexus'; //either of those imports works, but not both!
import {Mercedes} from 'src/js/classes/Mercedes'; //either of those imports works, but not both!

export class Car {
  constructor(make) {
    this.make = make;
  }

  static factory(msg) {
    switch(msg) {
      case "Lexus":
        return new Lexus();
      case "Mercedes":
        return new Mercedes();
    }
  }
}

and app.js:

import {Lexus} from 'src/js/classes/Lexus';
import {Mercedes} from 'src/js/classes/Mercedes';
import {Car} from 'src/js/classes/Car';

var car = Car.factory("Lexus");
console.log(car);

The interesting thing, if I import either Lexus or Mercedes to the Car class and call the factory method in app.js - everything works fine; however if I import both Lexus and Mercedes to the Car class I got an error:

Super expression must either be null or a function, not undefined

What do I miss ?

1 Answers
Related