2
I am trying to import a class, but I am making one or several mistakes. Can anyone enlighten me about?
Filing cabinet js/calendar
:
export default class Calendar {
constructor(date) {
console.log(date);
}
}
Filing cabinet index.html
(note that I am trying to import the class Calendar
):
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Calendar</title>
</head>
<body>
<div id="calendar"></div>
<script>
import { Calendar } from './js/calendar';
var calendar = new Calendar('2020-02-01');
</script>
</body>
</html>
However, I am getting this error:
SyntaxError: import declarations may only appear at top level of a module
import { Calendar } from './js/calendar'
– bfavaretto
I already tried this, it returns me this error: "Syntaxerror: import declarations may only appear at top level of a module"
– Marcio Andre
In HTML
<script type="module">
– Augusto Vasques