Import export in js

Hi,

Anyone have an idea why this won’t work?
I am just trying to get the data from my object to use in app.js, and I do not get and do not get something loggede to the console?

App.js

import {redDeck} from './redDeck.mjs';

alert(redDeck.Card1.name);

 

body.onload = function test(){

    console.log(redDeck.Card1.name);

}

redDeck.mjs

var redDeck = {

    Card1 : {

        name : "Amoured Troll",

        price : 2,

        attack : 1,

        health : 3,

        special : "Taunt"

    }

}

 

export default redDeck;

With export default you’re exporting whole redDeck, not the object with it, so you need one of two options for your first line in App.js:

// 1
import redDeck from './redDeck.mjs';

// 2
import { Card1 } from './redDeck.mjs';
1 Like

Ahh okay, and then i had the issue with cannot use import statement outside a module, but that was simply because i had not defined the type of the src i was importing in the HTML head.

Thank you iiiked :blush: