Export and Import Javascript

Export and Import Javascript


I am trying to export a module to another js file but I can’t see to make this work for some reason.

My root folder looks like this: root > css, img, js, sass and some html files. Within the js folder I have two js files: app.js and Data.js

This is how I am trying to do the export: export const data = [1, 2, 3, 4, 5]; from the Data.js file. As for the import: import {data} from './Data.js'; to the app.js file.

When I try to console.log(data); I get an error in the console: “Unexpected token {”

What am I missing here?

edit: import {data} from './Data'; this doesn’t work either…


How is your module builder set up?


Nvm, I thought I didn’t need a module builder to use these features, but then I found out that I do. I have to delete this question :sweat_smile:

Thanks for replying btw.