【发布时间】:2018-10-14 10:05:18
【问题描述】:
我正在测试一个电子应用程序,但我遇到了这个有害的错误:
“TypeError:无法读取未定义的属性'on'”
我所做的研究指出了一个拙劣的模块安装、一个语法问题,或者将一个未定义的变量传递给了 app.on,我怀疑这个问题可能是 Electron 被错误地指向(现在它被指向了)到以 electron\dist\electron.exe 结尾的文件夹,我听说可能不是正确的位置),但我不确定。
尽管检查了 require 命令、语法、重新检查、卸载和重新安装节点,但我似乎无法让这个该死的错误消失。这可能是什么原因造成的?
const electron = require('electron');
const os = require('os');
const fs = require('fs');
const app = electron.app;
const BrowserWindow = electron.BrowserWindow;
var Mousetrap = require('mousetrap');
const path = require('path');
const url = require('url');
const ipc = electron.ipcMain;
let mainWindow;
function createWindow () {
// Create the browser window.
mainWindow = new BrowserWindow({width: 800, height: 600})
// and load the index.html of the app.
mainWindow.loadURL(url.format({
pathname: path.join(__dirname, 'index.html'),
protocol: 'file:',
slashes: true
/* More code in this and sub functions*/
}))
}
})
const preferencesManager = require('./preferencesManager');
/******
Send data to database given constructor created in preferencesManager
******/
// First instantiate the class because we want to turn the class into an object to be able to use.
const store = new Store({ //create a new getting and setting logic
//We'll call our data file 'user-preferences'
configName: 'user-preferences',
defaults: {
//800 x 600 is the default size of our window
windowBounds: { width: 800, height: 600}
}
});
// When our app is ready, we'll create our BrowserWindow
app.on('ready',function(){
//Set up a listener for what I've done in keycapture (in the renderer process)
//???
ipc.on('invokeAction', function(event, args){
/* Do some action */
});
});
【问题讨论】:
-
我用 node index.js 测试了你的代码,它抛出了这个确切的错误。
-
找到任何解决方案了吗?