Search code examples
node.jselectronelectron-packager

electron-packager win32 don't open window


I have tried to build a very simple app with Electron, Node and AngularJS. The app is working well till I pack it. After packing, it doesn't show the window.

The ideea was to run a NodeJS process on localhost:5000, then to load the url in ElectronJS main window. When I double-click on .exe file, the process is starting at localhost:5000 and it's working in the browser only, but the Electron window is not shown.

Also, It crash when trying to open with 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.


Solution

  • I discovered that is a versioning incompatibility. At least, in my case was.

    The following combination fixed my problem:

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