Search code examples
javascripthtmles6-modulesscript-tag

Import does not works (Unexpected identifier)


Can someone help me with that? I'm trying to solve this problem, but I can't. I was looking for the answer on google but couldn't find it. I mean that I was trying to do it like other people but it still does not work.

I have 2 files in my src folder. I got index.js and paddle.js. In paddle.js I have defined a class Paddle with constructor and other methods. When I would like to export that class as default and then import it to my index.js file it does not works. Could someone help me please? Every time when I'm trying to import it error message appear in my console.


Solution

  • You need to include the importing script with type="module".

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