无法读取电子 javascript 中未定义的属性“on"

Cannot read property #39;on#39; of undefined in electron javascript(无法读取电子 javascript 中未定义的属性“on)
本文介绍了无法读取电子 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.

未捕获的类型错误:无法读取未定义的属性on"目的.(H:electricmain.js:12:4) 在对象处.(H:electricmain.js:63:3) 在 Module._compile (module.js:571:32) 在Module.load 中的 Object.Module._extensions..js (module.js:580:10)(module.js:488:32) 在 tryModuleLoad (module.js:447:12) 在Module.require 处的 Function.Module._load (module.js:439:3)(module.js:498:17) 在需要 (internal/module.js:20:19) 在file:///H:/electric/views/login.html:2:3

Uncaught TypeError: Cannot read property 'on' of undefined at Object. (H:electricmain.js:12:4) at Object. (H:electricmain.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.js 运行 electron.你的 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"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

在开发JS过程中,会经常遇到两个小数相运算的情况,但是运算结果却与预期不同,调试一下发现计算结果竟然有那么长一串尾巴。如下图所示: 产生原因: JavaScript对小数运算会先转成二进制,运算完毕再转回十进制,过程中会有丢失,不过不是所有的小数间运算会
问题描述: 在javascript中引用js代码,然后导致反斜杠丢失,发现字符串中的所有\信息丢失。比如在js中引用input type=text onkeyup=value=value.replace(/[^\d]/g,) ,结果导致正则表达式中的\丢失。 问题原因: 该字符串含有\,javascript对字符串进行了转
Rails/Javascript: How to inject rails variables into (very) simple javascript(Rails/Javascript:如何将 rails 变量注入(非常)简单的 javascript)
CoffeeScript always returns in anonymous function(CoffeeScript 总是以匿名函数返回)
Ordinals in words javascript(javascript中的序数)
getFullYear returns year before on first day of year(getFullYear 在一年的第一天返回前一年)