我有一个html文件,该文件加载了两个脚本:utils.js
和background.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>