require(“ electron”)。app未定义。我npm安装了新模块。不确定该怎么办 [英] require("electron").app is undefined. I npm installed fresh modules. Unsure what to do
问题描述
昨天,我在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安装
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 is not installed globally. Everything should be self contained in the directory.
此代码大部分来自电子样板
编辑:
主要过程:
'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.
对于在那里的任何人。与您的香草终端机或什至是编辑器一起仔细检查,以进行仔细检查。
For anyone out there. Double check with your vanilla terminal or even editor to double check.
这篇关于require(“ electron”)。app未定义。我npm安装了新模块。不确定该怎么办的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!