While trying the electron using their Quick Start here. I encountered a weird problem. Searching on google yields no results.
following is my directory tree
.
├── index.html
├── main.js
├── node_modules
│ └── electron-prebuilt
└── package.json
contents of package.json
{
"name": "desktop-widget",
"version": "1.0.0",
"main": "main.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"electron": "^0.4.1",
"electron-prebuilt": "^0.36.7"
},
"devDependencies": {},
"description": ""
}
contents of main.js
'use strict';
const electron = require('electron');
const app = electron.app;
const BrowserWindow = electron.BrowserWindow;
var mainWindow = null;
app.on('ready', function() {
mainWindow = BrowserWindow({width: 800, height: 600});
mainWindow.loadURL('file://', __dirname, 'index.html');
mainWindow.on('closed', function() {
mainWindow = null;
})
});
on running the command node_modules/electron-prebuilt/dist/electron .
i get the following error:

That was real silly of me
I missed the new keyword.
plus my loadURL function call is wrong (though i encountered it later and had nothing to do with the above error). In all, this final thing worked for me:
main.js
'use strict';
const electron = require('electron');
const app = electron.app;
const BrowserWindow = electron.BrowserWindow;
var mainWindow = null;
app.on('ready', function() {
mainWindow = new BrowserWindow({width: 800, height: 600});
mainWindow.loadURL('file://' + __dirname + '/index.html');
mainWindow.on('closed', function() {
mainWindow = null;
})
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With