I am trying to import a function from another javascript file but an error occurs with the import statement in main.js
.
main.js
:
import {Event} from 'event.js';
let asdf = new Event("hi", "hi", "hi");
console.log(asdf.title);
console.log(asdf.mainText);
console.log(asdf.buttonSet);
event.js
:
export function Event(title, mainText, buttonSet) {
this.title = title;
this.mainText = mainText;
this.buttonSet = buttonSet;
}
I looked up the syntax and don't see anything wrong:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import
Also, I ran the code snippet in this link and got the same error. ES6 in the browser: Uncaught SyntaxError: Unexpected token import
Edit: Corrected index.html file:
<script src="scripts/main.js" type="module"></script>