javascript - 电子应用程序中未定义require
问题描述
我是电子新手。在学习它时,我require not define
在浏览器窗口上遇到了错误。所以我搜索了一下,发现我们应该添加 nodeIntegration: true,
,所以我做到了,但它仍然没有解决我的问题。
这是我的 app.js(入口文件)
function createWindow() {
win = new BrowserWindow({
webPreferences: {
nodeIntegration: true,
},
});
win.loadURL(
url.format({
pathname: path.join(__dirname, "index.html"),
protocol: "file",
slashes: true,
})
);
win.on("close", () => {
win = null;
});
}
app.on("ready", createWindow);
和我的 index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>main renderer</title>
<link rel="stylesheet" href="./styles.css">
</head>
<body>
<h1>main renderer</h1>
<script>
require("./index.js")
</script>
</body>
</html>
解决方案
推荐阅读
- sql - 希望在 Snowflake SQL 中分解或取消嵌套到数组中
- python-3.x - django 未被识别为内部或外部命令
- python - 如何禁用和启用 python tkinter 框架中的所有小部件
- stenciljs - 如何在模板组件中导入 json 文件
- rust - 如何将通用结构作为函数参数
- numpy - 从具有列名和行名的文件中读取矩阵
- reactjs - 反应如何从 openweathermap 接收 3 小时降雨预报(数字错误后直接识别标识符)
- django - Django AttributeError:'str'对象没有属性'pk'?
- html - 无法同时在我的标题和导航栏上使用 justify-content 和 align-items
- python - 有人能告诉我为什么我得到“无”作为输出吗?