SyntaxError: import declarations may only appear at top level of a module, how to fix?

Viewed 2491

I'm importing import { io } from "./socket.io-client"; at the top of app.js, but I get this error SyntaxError: import declarations may only appear at top level of a module. I have a script tag under body like this:

<script src="app.js"></script>

What should I do to fix the error?

1 Answers

<script type="module" src="app.js"></script>

Related