"Cannot Use import statement outside a module"错误



我不知道如何解决这个错误,是创建一个模块还是其他什么。RequireJS不起作用,因为我使用的是浏览器。如何使用基于客户端的代码解决此错误?我需要安装程序包来解决它吗?请帮忙。

BTW我的JS代码:

import floor from 'mathjs';
import random from 'mathjs';
var colorValue = Array("#000000", "#000000", "#000000");
const hexadecimal = Array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D","E","F");
listening();


function listening() {
document.getElementById("changeColorOne").addEventListener(click, changeColor1);
document.getElementById("changeColorTwo").addEventListener(click, changeColor2);
document.getElementById("changeColorThree").addEventListener(click, changeColor3);
}
function changeColor1() {
document.querySelector(".square1").style.background = colorValue[0];
colorValue[0] = colorDecide();
}
function changeColor2() {
document.querySelector(".square2").style.background = colorValue[1];
colorValue[1] = colorDecide();
}
function changeColor3(){
document.querySelector(".square3").style.background = colorValue[2];
colorValue[2] = colorDecide();
}
function colorDecide() {
var tempValue = "#";
for (var i = 1; i <= 6; i++) {
let x = floor(random() * 16);
tempValue = tempValue.concat(hexadecimal[x]);
}
return tempValue;
}

为了使用本机importexport语句,您必须对系统进行模块化。

<script src="script.js" type="module"></script>

有关模块的更多信息`

相关内容

最新更新