問題描述
我正在嘗試運行此代碼,但每次都收到此錯誤消息.首先,我全局安裝了 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"的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!