【问题标题】:Electron app won't open after compiling for Win32 x64为 Win32 x64 编译后,Electron 应用程序无法打开
【发布时间】:2020-12-27 15:05:21
【问题描述】:

我有一个问题。我正在用电子创建一个应用程序,当我将它编译成一个它构建的 .exe 文件时,它还没有在我的笔记本电脑上启动/创建一个窗口。我尝试关闭我的 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.

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

【问题讨论】:

    标签: javascript c++ node.js electron 64-bit


    【解决方案1】:

    您的构建命令似乎错误。

    请参阅electron-packager 中的the docs 以获取命令签名:

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

    您在mkdir build &amp;&amp; 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
    

    【讨论】:

    • 我现在试试这个
    • 有同样的问题(我也在使用 Angular),显然是通过electron-builder 而不是通过electron-packager 构建的。使用@pergy 解决方案后效果很好。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-26
    • 1970-01-01
    • 2023-02-11
    • 2017-11-16
    • 2020-05-07
    相关资源
    最近更新 更多