的index.html
<html>
<head>
<script type="module">
import {answer} from './code.js'
console.info("It's ${answer()} time!")
</script>
</head>
<body>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
code.js
export function answer(){
return 'module';
}
Run Code Online (Sandbox Code Playgroud)
错误:CORS策略阻止了对来自'null'的'file:/// C:*******/es6/code.js'中的脚本的访问:响应无效.因此不允许原点'null'访问.
Chrome表示它可以支持模块,我已经看到了在网络上运行的示例,但是当我复制下载并在本地运行它们时,我总是得到上面的错误.我不想使用Babel,Webpack等.
我尝试在Chrome和Chrome Canary中启用实验性Web平台功能标志.
javascript google-chrome module same-origin-policy ecmascript-6