[英]Electron app won't open after compiling for Win32 x64
I have an issue.我有一个问题。 I was creating an app with electron and when I compiled it to an .exe file it built, but haven't started/created a window on my laptop.
我正在用电子创建一个应用程序,当我将它编译为它构建的 .exe 文件时,但还没有在我的笔记本电脑上启动/创建一个窗口。 I tried turning off my Windows Defender but that didn't help.
我尝试关闭我的 Windows Defender,但这没有帮助。 Whenever I try to run it with my npm script
npm start
or electron .
每当我尝试使用我的 npm 脚本
npm start
或electron .
运行它时electron .
it works.有用。 Is there anything that I'm doing wrong?
有什么我做错了吗?
I run the npm run build
script which will execute我运行将执行的
npm run build
脚本mkdir build && electron-packager build ISS-Live-Locator --platform=win32 --arch=x64
I copied this main.js
file from the electron documentation.我从电子文档中复制了这个
main.js
文件。 And updated my app structure accordingly.并相应地更新了我的应用程序结构。
// Modules to control application life and create native browser window
const {app, BrowserWindow} = require('electron')
const path = require('path')
function createWindow () {
// Create the browser window.
const mainWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
preload: path.join(__dirname, 'preload.js')
}
})
// and load the index.html of the app.
mainWindow.loadFile('index.html')
// Open the DevTools.
// mainWindow.webContents.openDevTools()
}
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.whenReady().then(() => {
createWindow()
app.on('activate', function () {
// On macOS it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (BrowserWindow.getAllWindows().length === 0) createWindow()
})
})
// Quit when all windows are closed, except on macOS. There, it's common
// for applications and their menu bar to stay active until the user quits
// explicitly with Cmd + Q.
app.on('window-all-closed', function () {
if (process.platform !== 'darwin') app.quit()
})
// In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and require them here.
Thank you!谢谢! Hope this made sense.
希望这是有道理的。
Your build command seems wrong.您的构建命令似乎有误。
See the docs of electron-packager
for the command's signature:有关命令的签名,请参阅
electron-packager
的文档:
electron-packager <sourcedir> <appname> --platform=<platform> --arch=<arch> [optional flags...]
What you do in mkdir build && electron-packager build ISS-Live-Locator --platform=win32 --arch=x64
is basically trying to use the newly created build
folder as source directory.您在
mkdir build && electron-packager build ISS-Live-Locator --platform=win32 --arch=x64
基本上是尝试使用新创建的build
文件夹作为源目录。 Therefore, your app should be empty and can't run.因此,您的应用程序应该是空的并且无法运行。
Also, you should get Unable to determine Electron version. Please specify an Electron version
此外,您应该
Unable to determine Electron version. Please specify an Electron version
Unable to determine Electron version. Please specify an Electron version
error because you don't specify electron version. Unable to determine Electron version. Please specify an Electron version
错误,因为您没有指定电子版本。
Try this build command instead:试试这个构建命令:
electron-packager . ISS-Live-Locator --platform=win32 --arch=x64 --electronVersion=10.1.1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.