javascript标识符
If you are using the import
statement to import different files in your JavaScript application, you might find the browser giving you this error: Unexpected Identifier.
如果使用import
语句在JavaScript应用程序中导入其他文件,则可能会发现浏览器出现以下错误: Unexpected Identifier 。
Why? And how can you make ES6 modules work in browsers?
为什么? 以及如何使ES6模块在浏览器中工作?
You just have to do one tiny change: instead of loading your main entry point JavaScript file using
您只需要做一个小小的更改:无需使用加载主入口点JavaScript文件
<script src="index.js"></script>
add type="module"
:
添加type="module"
:
<script type="module" src="index.js"></script>
and things should now work fine.
现在一切正常。
翻译自: https://flaviocopes.com/how-to-solve-unexpected-identifier-modules/
javascript标识符