我正在尝试开始使用 Electron。我已经能够运行所有简单的示例。它们都按预期工作。当我尝试按照快速入门指南我遇到同样的问题,因为在提到这个问题:应用程序启动正常,但不显示节点Chrome和电子的版本。当我查看开发工具时,我看到了这个错误:
Uncaught ReferenceError: process is not defined
at index.html:14
Run Code Online (Sandbox Code Playgroud)
但是,我已经设置nodeIntegration为true.
为什么它仍然不起作用?
版本:
操作系统:
索引.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Hello World!</title>
<meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-inline';" />
</head>
<body style="background: white;">
<h1>Hello World!</h1>
<p>
We are using node
<script>document.write(process.versions.node)</script>,
Chrome
<script>document.write(process.versions.chrome)</script>,
and Electron
<script>document.write(process.versions.electron)</script>.
</p>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
主文件
const { app, BrowserWindow } = require('electron')
function createWindow …Run Code Online (Sandbox Code Playgroud) 我是 Electron 的新手,我真的一直在努力让它工作。我遇到了无法解释的行为,所以总结一下:我无法使 Electron 和 html 之间的通信正常工作
“未捕获的 ReferenceError:需要未定义”在网站内,即使我有 nodeIntegration:true
File Tree:
./
index.html
index.js
package-lock.json
package.json
node_modules/
Run Code Online (Sandbox Code Playgroud)
索引.js:
const electron = require("electron");
const Ffmpeg = require("fluent-ffmpeg");
const CmdExec = require('child_process');
const {
app,
BrowserWindow,
ipcMain
} = electron;
function createWindow() {
//If I put the main window ini into here, and then call app.on("ready", createWindow()); app says
//"Cant create window before ready", even though I just moved the funcion from inside ready to here..
}
app.on('ready', () => { …Run Code Online (Sandbox Code Playgroud)