require(“electron").app 未定义.我 npm 安装了新的模块.不确定该怎么做 [英] require("electron").app is undefined. I npm installed fresh modules. Unsure what to do

查看:54
本文介绍了require(“electron").app 未定义.我 npm 安装了新的模块.不确定该怎么做的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

昨天,我在 Electron 上开发得非常好.然后我跳到我的电脑上,发现 Electron 现在根本不工作了.

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

我删除了 node_modules 并做了一个新的 npm install

I removed node_modules and did a fresh npm install

package.json:

package.json:

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

这是我得到的错误.

我遵循了这个问题以前问题的建议.什么都解决不了.

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

Electron 没有全局安装.一切都应该包含在目录中.

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

npm 列表

大部分代码取自 电子样板

主进程:

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

推荐答案

所以,就我而言.通过使用我原来的终端而不是 Atom 的插件终端解决了问题.

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

对于外面的任何人.使用您的 vanilla 终端甚至编辑器仔细检查以进行仔细检查.

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

这篇关于require(“electron").app 未定义.我 npm 安装了新的模块.不确定该怎么做的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆