Chrome 61:意外的令牌导入 [英] Chrome 61: Unexpected token import

查看:134
本文介绍了Chrome 61:意外的令牌导入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用导入运行应支持模块加载的Chrome 61

Running Chrome 61 which is supposed to support module loading with import.

确实Paul's demo 适用于我。但是,当我自己尝试它时,我得到一个JS错误Unexpected token import。 Chrome似乎不愿意在导入

Indeed Paul's demo works for me. However, when I try it myself I get a JS error "Unexpected token import". Chrome seems to balk at import:

test.html

test.html

<!doctype html> 
<html>
<body>
<script src="test.js"></script>
</body>
</html>

test.js:

test.js:

import {hello} from './something.js'
console.log(hello())

something.js

something.js

export {hello}
function hello() {
    return "hello world"
}

为什么Chrome不能理解import

Why does Chrome not understand "import"

推荐答案

应该是< script type = module src = test.js> 。整个语法在模块脚本中被巧妙地改变(允许 import export ,以及严格模式是必需的) 。

That should be <script type=module src=test.js>. The entire syntax is subtly changed in module scripts (import and export are allowed, as well as strict mode being mandatory).

这篇关于Chrome 61:意外的令牌导入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆