5

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?

Padev
  • 51
  • 1
  • 2

1 Answers1

3

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

GyDi
  • 181
  • 4
  • 2
    Then I get this error `Loading module from “http://127.0.0.1:5500/socket.io-client” was blocked because of a disallowed MIME type (“text/html”).` – Padev Jul 06 '21 at 13:22
  • You should make sure that the path is correct. Is it `socket.io-client.js` ? – GyDi Jul 06 '21 at 13:25