【发布时间】:2021-06-11 05:08:42
【问题描述】:
我正在尝试开始使用 Electron。我已经能够运行所有simple examples。它们都按预期工作。当我尝试关注Quick Start Guide 时,我遇到了与this question 中提到的相同的问题:应用程序正常启动,但不显示节点 Chrome 和 Electron 的版本。当我查看开发工具时,我看到了这个错误:
Uncaught ReferenceError: process is not defined
at index.html:14
但是,我已经将nodeIntegration 设置为true。
为什么还是不行?
版本:
- npm 7.6.3
- 节点 v14.16.0
- 铬 89.0.4389.82
操作系统:
- Ubuntu 20.04.2 LTS。
index.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>
main.js
const { app, BrowserWindow } = require('electron')
function createWindow () {
const win = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true
}
})
win.loadFile('index.html')
}
app.whenReady().then(createWindow)
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit()
}
})
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow()
}
})
package.json
{
"name": "my-electron-app",
"version": "0.1.0",
"author": "username",
"description": "My Electron app",
"main": "main.js",
"scripts": {
"start": "electron ."
},
"devDependencies": {
"electron": "^12.0.0"
}
}
【问题讨论】:
标签: node.js linux npm electron chromium