为 Win32 x64 编译后电子应用程序无法打开

Electron app won't open after compiling for Win32 x64

我有一个问题。我正在用电子创建一个应用程序,当我将它编译为它构建的 .exe 文件时,但我的笔记本电脑上没有 started/created window。我尝试关闭我的 Windows Defender,但这没有帮助。每当我尝试使用我的 npm 脚本 npm startelectron . 运行 它时,它都会起作用。我做错了什么吗?

我 运行 npm run build 脚本将执行
mkdir build && electron-packager build ISS-Live-Locator --platform=win32 --arch=x64

我从电子文档中复制了这个 main.js 文件。并相应地更新了我的应用程序结构。

// 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.

谢谢! 希望这是有道理的。

您的构建命令似乎有误。

请参阅 electron-packagerthe docs 命令签名:

electron-packager <sourcedir> <appname> --platform=<platform> --arch=<arch> [optional flags...]

您在 mkdir build && electron-packager build ISS-Live-Locator --platform=win32 --arch=x64 中所做的基本上是尝试使用新创建的 build 文件夹作为源目录。因此,您的应用应该是空的,不能 运行.

此外,您应该得到 Unable to determine Electron version. Please specify an Electron version 错误,因为您没有指定电子版本。

试试这个构建命令:

electron-packager . ISS-Live-Locator --platform=win32 --arch=x64 --electronVersion=10.1.1