Require ("electron"). app undefined. I npm installed fresh modules. Not sure what to do

Yesterday I developed very well on Electron. Then I jump onto my computer to understand that Electron is not working right now.

I deleted node_modulesand made a new onenpm install

package.json:

...
"devDependencies": {
    "devtron": "^1.4.0",
    "electron": "^1.4.7"
  },
"dependencies": {
    "electron-debug": "^1.1.0"
  }
...

This is the error I received.

I followed suggestions from previous releases of this issue. Nothing permits this.

The electron is not installed globally. Everything should be included in the catalog.

npm list

Most of this code was taken from an electronic template.

Edit:

main process:

'use strict';

const path = require('path');
const electron = require('electron');
const app = electron.app;

// adds debug features like hotkeys for triggering dev tools and reload
require('electron-debug')({
    showDevTools: true
});

// prevent window being garbage collected
let mainWindow;

function onClosed() {
    // dereference the window
    // for multiple windows store them in an array
    mainWindow = null;
}

function createMainWindow() {
    const display = electron.screen.getPrimaryDisplay();

    const win = new electron.BrowserWindow({
        width: display.workArea.width,
        height: display.workArea.height
    });

    const projectPath = path.dirname(path.dirname(__dirname));

    win.loadURL(`file://${projectPath}/static/index.html`);
    win.on('closed', onClosed);

    return win;
}

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

app.on('activate', () => {
    if (!mainWindow) {
        mainWindow = createMainWindow();
    }
});

app.on('ready', () => {
    mainWindow = createMainWindow();
});
+4
source share
1 answer

, . , Atom.

. .

+11

Source: https://habr.com/ru/post/1661104/


All Articles