electron-packager win32 打不开window

electron-packager win32 don't open window

我尝试使用 Electron、Node 和 AngularJS 构建一个非常简单的应用程序。在我打包之前,该应用程序运行良好。打包后不显示window.

想法是在 localhost:5000 上 运行 一个 NodeJS 进程,然后在 ElectronJS main window 中加载 url。当我双击 .exe 文件时,该进程从 localhost:5000 开始,它仅在浏览器中运行,但未显示 Electron window。

此外,尝试使用 npm run start / npm start

打开时崩溃

"Windows Script Host. Error: Syntax error. Code: 800A03EA. Source: Microsoft JScript compilation error."

package.json

  "scripts": {
    "start": "electron ."
  }

server.js

'use strict';
const
express = require('express'),
app = express();

app.set('port', (5000));
app.use(express.static('app'));
app.use(express.static('dist'));
app.use(express.static('node_modules'));

app.get("*", (req,res)=>{
    res.sendFile(__dirname+"/app/index.html");
});

app.listen(app.get('port'), function() {
    console.log("Node server is running at localhost:" + app.get('port'));
});

electron.js

'use strict';
const 
electron = require('electron'),
server = require('./server.js'),
{app, BrowserWindow} = electron;

app.on('ready', () => {
    var win = new BrowserWindow({
        show: false,
        width: 800,
        height: 600
    });

    win.loadURL("http://localhost:5000/");

    win.on('ready-to-show', function() {
        win.show();
        win.focus();
    });

    win.on('closed', () => {
        win = null
    });
});

I can find the process in task manager.

NodeJS is running on localhost:5000. I can see it in the browser.

我看不出您的代码有任何问题。但我确实发现了一个可能影响您的相关问题:https://github.com/electron/electron/issues/7779

你能在调试模式下启动 electron 并检查 ready-to-show 事件是否触发了吗?

我发现这是版本不兼容问题。至少,对我来说是。

以下组合解决了我的问题:

"electron": "^3.0.4" with "electron-packager": "^12.2.0"