【问题标题】:Electron: Crash after build exe电子:构建exe后崩溃
【发布时间】:2021-06-26 14:14:06
【问题描述】:

我正在尝试将 wiki.jselectron 合并
而且,我可以像下面的代码一样制作简单的电子应用程序

ma​​in.js

const { app, BrowserWindow } = require('electron');
const path = require('path')

var winGlobal;

// This will run express server with port 3000 within 3~6 seconds
require('./server/index.js')

// load the url after 9 seconds.
setTimeout(() => winGlobal.loadURL('http://localhost:3000'), 9000);

function createWindow() {
    const win = new BrowserWindow({
        width: 1200,
        height: 900,
        webPreferences: {
            //   preload: path.join(__dirname, 'preload.js')
        }
    })
    winGlobal = win;
}

app.whenReady().then(() => {
    createWindow()

    app.on('activate', () => {
        if (BrowserWindow.getAllWindows().length === 0) {
            createWindow()
        }
    })
})

app.on('window-all-closed', () => {
    if (process.platform !== 'darwin') {
        app.quit()
    }
})

package.json

{
    ...
    "main": "main.js"
    ...
    "build": {
        "productName": "wiki.js-electron",
        "appId": "com.electron.wiki",
        "directories": {
          "output": "build"
        },
        "asar": true
    },

    "dependencies": {
        ...
        "express": "4.17.1",
        "sqlite3": "5.0.0",
        ...
    }
    "devDependencies": {
        ...
        "electron": "^12.0.2",
        "electron-builder": "^22.10.5",
        ...
    }
}

而且,我可以使用npx electron . 运行当前项目

要构建 exe,我可以用npx electron-build 构建,并生成新的 exe 文件而没有错误日志。

但是,exe是崩溃的,没有任何错误。

我该如何解决这个问题?


完整源码Github:https://github.com/nkhs/wiki.js-electron
内置exe:https://wetransfer.com/downloads/535a59714d4d957f478c14816ee0142e20210330143018/0d5cbe

【问题讨论】:

    标签: javascript node.js electron electron-builder wiki.js


    【解决方案1】:

    我找到了解决方案 我没有在文件资源管理器上双击鼠标运行,而是使用 windows 命令提示符运行 exe,然后从那里可以找到错误日志。

    所以,我发现:某些相对路径不起作用,因为电子包源代码带有 asar。

    并且,某些文件操作不起作用,等等fs.readfs.readDir

    Cannot access files inside asar archive in electron app,


    所以,我删除了这个问题。

    【讨论】:

      猜你喜欢
      • 2019-10-16
      • 2021-01-02
      • 1970-01-01
      • 2017-03-30
      • 2021-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多