无法读取电子javascript中未定义的属性“ on” [英] Cannot read property 'on' of undefined in electron javascript

查看:121
本文介绍了无法读取电子javascript中未定义的属性“ on”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试运行此代码,但是每次收到此错误消息时。首先,我在全球范围内安装了 npm 。然后我将其安装在我的应用程序中,但仍然出现相同的错误。

I am trying to run this code but every time I am getting this error message. First I installed npm globally. Then I installed it within my app but still getting same error.


未捕获到的TypeError:无法读取$ b $上未定义的属性 on b对象。 (H:\electric\main.js:12:4)在Object。
(H:\electric\main.js:63:3)在Module._compile(module.js:571:32)在
Object.Module._extensions..js(module.js) :580:10)在Module.load
(module.js:488:32)在tryModuleLoad(module.js:447:12)在
Function.Module._load(module.js:439: 3)在Module.require
(module.js:498:17)在require(internal / module.js:20:19)在
file:/// H:/ electric / views / login .html:2:3

Uncaught TypeError: Cannot read property 'on' of undefined at Object. (H:\electric\main.js:12:4) at Object. (H:\electric\main.js:63:3) at Module._compile (module.js:571:32) at Object.Module._extensions..js (module.js:580:10) at Module.load (module.js:488:32) at tryModuleLoad (module.js:447:12) at Function.Module._load (module.js:439:3) at Module.require (module.js:498:17) at require (internal/module.js:20:19) at file:///H:/electric/views/login.html:2:3



const electron = require('electron');
const {Menu} = require('electron');
const {app} = require('electron');
const {BrowserWindow} = require('electron');
const conn = require('mysql');
const path = require('path');
const url = require('url');

// const app = electron.app;
// const BrowserWindow = electron.BrowserWindow;
var mainWindow = null;
app.on('ready', function () {
    mainWindow = new BrowserWindow({ width: 1024, height: 768, backgroundcolor: '#2e2c29' });
    mainWindow.loadURL(url.format({
        pathname: 'popupcheck.html',
        protocol: 'file:',
        slashes: true
    }));enter code here
    mainWindow.webContents.openDevTools();
    mainWindow.setProgressBar(1);
});`][1]


推荐答案

我想您正在尝试使用node运行电子。您的package.json看起来像这样吗?

I guess you are trying to run electron using node. Does your package.json look like this?

{
    "scripts": {
        "start": "node main.js"
    }
}

请更改运行像这样的电子应用

please change to run electron app like this

{
    "scripts": {
        "start": "electron ."
    }
}

应该可以工作

注意::这对于通过以下命令将电子安装到全局的人来说是额外的

note: this is extra for somebody that install electron to global with command something like this

npm install -g electron

当您要在代码中使用电子 require(electron),您应该使用此命令将全局路径链接到当前目录

when you want to use electron in the code require(electron) you should link the global path to your current directory by using this command

npm link electron

这篇关于无法读取电子javascript中未定义的属性“ on”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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