Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

es6 import var not defined in code importing

For some reason when I do var sphere = new Core(); in Game, I see Core is undefined, even though I import it:

Game.js

  import Core from 'gameUnits/Core' 

    export class Game { 
    constructor() {

Core.js:

export class Core {
    constructor(scene) {
    }
}
like image 931
SuperUberDuper Avatar asked Dec 25 '22 00:12

SuperUberDuper


1 Answers

When you make import without curly brackets you're trying to import default object of the module.

So, you must add default keyword to your Core exporting:

export default class Core {
    constructor(scene) {
    }
}

OR place your Core importing into curly brackets:

import { Core } from 'gameUnits/Core';

Look here for more informaction about ECMAScript 6 modules

PS: Using default keyword you can specify ANY name for Core class. For example:

import GameUnitsCore from 'gameUnits/Core';
like image 196
alexpods Avatar answered Feb 27 '23 04:02

alexpods