I am following the Electron quick start guide, it works without any errors, but the output is not as described in the docs, the versions with document.write
wont show up in the output.
This is my output:
Hello World!
We are using node , Chrome , and Electron .
My expected output would include the corresponding version numbers.
I have checked the GitHub page of the app, still the same, tried various StackOverflow answers but none worked for me.
index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Hello World!</title>
</head>
<body>
<h1>Hello World!</h1>
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>.
</body>
</html>
package.json
{
"name": "electronapp",
"version": "1.0.0",
"description": "",
"main": "main.js",
"scripts": {
"start": "electron ."
},
"author": "harsh",
"license": "ISC",
"devDependencies": {
"electron": "^5.0.2"
}
}
main.js
const {app, BrowserWindow} = require('electron')
const path = require('path')
let mainWindow
function createWindow () {
mainWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
preload: path.join(__dirname, 'preload.js')
}
})
mainWindow.loadFile('index.html')
mainWindow.on('closed', function () {
mainWindow = null
})
}
app.on('ready', createWindow)
app.on('window-all-closed', function () {
if (process.platform !== 'darwin')
app.quit()
})
app.on('activate', function () {
if (mainWindow === null)
createWindow()
})
I have Node globally installed, and Chrome is packaged with Electron, right?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…