Es6 import var not defined when importing code

For some reason, when I do var sphere = new Core (); In the game, I see that Core is undefined, although I import it:

Game.js

  import Core from 'gameUnits/Core' 

    export class Game { 
    constructor() {

core.js:

export class Core {
    constructor(scene) {
    }
}
+4
source share
1 answer

When you import without curly braces, you are trying to import the default module object.

So you should add a defaultkeyword to your Coreexport:

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

OR put your Coreimport in braces:

import { Core } from 'gameUnits/Core';

Look here for more information on ECMAScript 6 modules

PS. default, Core. :

import GameUnitsCore from 'gameUnits/Core';
+10

Source: https://habr.com/ru/post/1569692/


All Articles