Search code examples
javascriptecmascript-6ecmascript-harmony

ES6 Class is not a function when imported via System


how come Game is not a function when imported via System

import Core from 'gameUnits/Core' 

export class Game { 
constructor() {

core:

export class Core {
    constructor(scene) {
    }
}

etc

and in the browser:

     <script src="bower_components/traceur/traceur.js"></script>
  <script src="bower_components/es6-module-loader/dist/es6-module-loader.js"></script>
  <script>
    System.import('Game').then(function (Game) {
      game = new Game();
    });
  </script>

Solution

  • The module object in your case isn't Game, it contains Game. Try:

    System.import('Game').then(function ({Game}) {
      game = new Game();
    });