I want to use import
in Javascript, but I cannot get it to work (Firefox 65.0.2 on Fedora 28).
I have this in my HTML:
<!DOCTYPE html>
<html>
<head>
<script src="js/App.js" type="module"></script>
<script type="text/javascript">
$(function() {
application = new App(true);
});
</script>
</head>
</html>
and in my js/App.js
:
import "js/Helpers.js"
class App {
constructor(needsLogin) {
}
}
with js/Helpers.js
being
class Helpers {
}
but, when run, I get this error:
ReferenceError: App is not defined
I tried adding import
above the new App()
call, but that gives me
SyntaxError: import declarations may only appear at top level of a module
How can I import Helpers.js
in my App.js
?