简体   繁体   English

未捕获的类型错误:无法读取未定义的属性“on”。 我也尝试重新安装电子

[英]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.请尝试这些可能的解决方案。

  1. 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');
  2. 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.

相关问题 无法读取未定义的属性“toFixed”。 未捕获的类型错误 - Cannot read property 'toFixed' of undefined. Uncaught TypeError TypeError:无法读取未定义的属性'addTopic'。 我是盲人吗? - TypeError: Cannot read property 'addTopic' of undefined. Am I blind? 我有错误未捕获的TypeError:无法读取未定义的属性'toLowerCase' - I have the error Uncaught TypeError: Cannot read property 'toLowerCase' of undefined “ typeError:无法读取未定义的属性“用户名”。” - “typeError: Cannot read property 'username' of undefined.” 未捕获的TypeError:无法读取未定义的属性'fn',电子2,角6? - Uncaught TypeError: Cannot read property 'fn' of undefined, electron 2, angular 6? 未捕获的类型错误:无法使用 Electron 更新程序代码读取未定义的属性“on” - Uncaught TypeError: Cannot read property 'on' of undefined with Electron updater code 带有 Electron 的 TestCafe 抛出“Uncaught TypeError: Cannot read property 'source' of undefined” - TestCafe with Electron throwing "Uncaught TypeError: Cannot read property 'source' of undefined" Uncaught TypeError:无法读取未定义的属性“ push”。 应该做什么? - Uncaught TypeError: Cannot read property 'push' of undefined. What should be done? 如何捕获未捕获的类型错误:无法读取未定义的属性'datatable'。 错误 - How to catch Uncaught typeerror: cannot read property 'datatable' of undefined. error 未捕获(承诺中)类型错误:无法读取未定义的属性“0”。 从 csv 文件中提取以填充数组 - Uncaught (in promise) TypeError: Cannot read property '0' of undefined. Pulling from a csv file to populate an array
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM