html页面报错Uncaught SyntaxError: Cannot use import statement outside a module

    如题所示,在我们学习es6的时候,使用export导出模块,使用import导入模块的语法时,我们需要将我们在html中声明的标签<script></script>类型type指定为module,简单代码如下:

     a.js

     html页面报错Uncaught SyntaxError: Cannot use import statement outside a module

    index.html

    html页面报错Uncaught SyntaxError: Cannot use import statement outside a module

    在浏览器中打开页面,查看控制台,会报如题所示的错误:

    html页面报错Uncaught SyntaxError: Cannot use import statement outside a module 

    报错的原因是用了es6的语法, 浏览器默认将它作为js解析会出现问题,需要将它作为模块导入,因此,我们需要将<script type="text/javascript"></script>修改为<script type="module"></script>,修改之后就会出现正确的结果:

    html页面报错Uncaught SyntaxError: Cannot use import statement outside a module