require(“electron”).app is undefined. I npm installed fresh modules. Unsure what to do

不羁岁月 提交于 2019-12-22 05:52:43

问题


Yesterday, I was developing on Electron perfectly fine. Then I hop onto my computer to realize Electron isn't working at all now.

I removed node_modules and did a fresh npm install

package.json:

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

This is the error I got.

I followed the suggestions used of previous issues of this problem. Nothing is resolving it.

Electron is not installed globally. Everything should be self contained in the directory.

npm list

Most of this code was taken from electron boilerplate

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();
});

回答1:


So, in my case. Issue was resolved by using my original terminal rather than a plugin terminal for Atom.

For anyone out there. Double check with your vanilla terminal or even editor to double check.



来源:https://stackoverflow.com/questions/40664009/requireelectron-app-is-undefined-i-npm-installed-fresh-modules-unsure-what

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!