Javascript 我的chrome扩展在添加导入后立即停止工作
当前代码可以工作并在单击按钮时发出警报,但是如果我将Javascript 我的chrome扩展在添加导入后立即停止工作,javascript,google-chrome-extension,Javascript,Google Chrome Extension,当前代码可以工作并在单击按钮时发出警报,但是如果我将myAlert移动到另一个文件并导入它,它将停止工作。有人知道发生了什么吗 manifest.json { "name": "Getting Started Example", "version": "1.0", "description": "Build an Extension!", "browser_action": { "default_popup": "popup.html" }, "manifest_
myAlert
移动到另一个文件并导入它,它将停止工作。有人知道发生了什么吗
manifest.json
{
"name": "Getting Started Example",
"version": "1.0",
"description": "Build an Extension!",
"browser_action": {
"default_popup": "popup.html"
},
"manifest_version": 2
}
popup.html
<!DOCTYPE html>
<html>
<head>
<style>
button {
height: 30px;
width: 30px;
outline: none;
}
</style>
</head>
<body>
<button id="changeColor"></button>
<script type="module" src="popup.js"></script>
</body>
</html>
myAlert是唯一导出的功能吗?如果是,请使用从“/alert”导入myAlert;结果仍然相同,导入后中断其他使用导出函数MyAlert()或导出默认函数MyAlert()。alert.js的内容是导出函数MyAlert(){…唯一可能的原因是您没有从正确的路径导入文件。请检查控制台和终端错误/警告。确保您的安装程序已准备好webpack/ES6。
// import { myAlert } from "./alert";
function myAlert() {
alert("hello");
}
let changeColor = document.getElementById('changeColor');
changeColor.onclick = myAlert;