导入已定义的const不会引发错误

时间:2019-05-09 08:16:13

标签: javascript google-chrome-extension ecmascript-6 firefox-webextensions es6-modules

我有一个html文件,该文件加载了两个脚本:utils.jsbackground.js

utils.js中,我定义了:

const test = 'a';

background.js中,我有:

import {test} from "./modules/hosts.js";  // no error here
console.log(test);                        // 'b' is printed

模块hosts.js定义:

const test = 'b';

我希望导入会失败,因为已经定义了test,但是导入有效,并且test模块中的值使host.js过载。
为什么起作用?

编辑:
HTML文件:

    <script type="application/javascript" src="utils/utils.js"></script>
    <script type="module" src="background.js"></script>

0 个答案:

没有答案