[英]Uncaught TypeError: Cannot read property 'on' of undefined. I have tried to reinstall electron as well
I am not able to remove an error mentioned:我无法删除提到的错误:
" Uncaught TypeError: Cannot read property 'on' of undefined "
“未捕获的类型错误:无法读取未定义的属性 'on' ”
I have tried to reinstall electron as well but still getting the same error.我也尝试重新安装电子,但仍然出现相同的错误。
const electron = require('electron');
const {BrowserWindow, Menu} = require('electron');
var app = electron.app;
const conn = require('mysql');
const path = require('path');
const url = require('url');
var mainWindow;
app.on('ready', function () {
mainWindow = new BrowserWindow({ width: 1024, height: 768,
backgroundcolor: 'black' });
mainWindow.loadURL(url.format({
pathname: 'dashboard.html',
protocol: 'file:',
slashes: true
}));
mainWindow.webContents.openDevTools();
mainWindow.setProgressBar(1);
});
"TypeError: Cannot read property 'on' of undefined" This means 'app' object has not been loaded properly from 'electron' module and the 'app.on()' method on 8th line, it has been called on undefined object 'app'.
“类型错误:无法读取未定义的属性 'on'”这意味着未从 'electron' 模块和第 8 行的 'app.on()' 方法正确加载 'app' 对象,它已在未定义的对象上调用'应用程序'。
Please try these possible solutions.请尝试这些可能的解决方案。
Replace代替
const electron = require('electron'); const {BrowserWindow, Menu} = require('electron'); var app = electron.app;
with和
var app = require('electron').app; const {BrowserWindow, Menu} = require('electron');
In Package.json file edit/add this line specifying the starting point for an application.在 Package.json 文件中编辑/添加这一行,指定应用程序的起点。
"script":{"start": "electron ."}
edit:编辑:
May be you have the npm electron module installed somewhere in your system(globally), it overrides the builtin electron module.可能是您在系统中的某处(全局)安装了 npm 电子模块,它会覆盖内置的电子模块。 You can find out the path of it by logging out
您可以通过注销找到它的路径
require.resolve('electron').
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.