(TypeError):无法读取属性';在';未定义Javascript电子的定义

(TypeError):无法读取属性';在';未定义Javascript电子的定义,javascript,electron,Javascript,Electron,学习electron和JavaScript——我来自swift,所以我不是很熟悉,我一直在我的调试器中学习?有什么想法吗?我有一个按钮,当点击它时,它应该做一些事情,但它不做它,当我调试时,这似乎是我能看到的唯一问题。不太确定我是否犯了错误,因为我使用了electron forge,所以没有在index.js中进行太多编码 const { app, BrowserWindow } = require('electron'); const path = require('path');

学习electron和JavaScript——我来自swift,所以我不是很熟悉,我一直在我的调试器中学习?有什么想法吗?我有一个按钮,当点击它时,它应该做一些事情,但它不做它,当我调试时,这似乎是我能看到的唯一问题。不太确定我是否犯了错误,因为我使用了electron forge,所以没有在index.js中进行太多编码

const { app, BrowserWindow } = require('electron');
const path = require('path');
        
if (require('electron-squirrel-startup')) { 
    app.quit();
}
    
const createWindow = () => {   
    const mainWindow = new BrowserWindow({
        width: 800,  
        height: 600,
        webPreferences : {
            nodeIntegration : true
        }
     });
    
     mainWindow.loadFile(path.join(__dirname, 'index.html'));
    
     mainWindow.webContents.openDevTools();
 };
     
 app.on('ready', createWindow);
 app.on('window-all-closed', () => {
     if (process.platform !== 'darwin') {
         app.quit();
     }
 });
    
 app.on('activate', () => { 
     if (BrowserWindow.getAllWindows().length === 0) {
         createWindow();
     }
 });
TypeError:无法读取未定义的属性“on”
index.js:27
反对。(/Users/raymondotoadese/my-app/src/index.js:27:5)
at模块编译(内部/modules/cjs/loader.js:1153:14)
at Object.Module._extensions..js(internal/modules/cjs/loader.js:1176:10)
在Module.load(内部/modules/cjs/loader.js:1000:32)
at Function.Module._load(内部/modules/cjs/loader.js:899:14)
在Function.executeUserEntryPoint[作为runMain](internal/modules/run_main.js:74:12)
在internal/main/run_main_module.js:18:47

那么失败的线路是什么?第一个
app.on
呼叫?该脚本是加载到主进程中,还是偶然加载到禁用了节点的渲染器中?
  TypeError: Cannot read property 'on' of undefined
index.js:27
    at Object.<anonymous> (/Users/raymondotoadese/my-app/src/index.js:27:5)
    at Module._compile (internal/modules/cjs/loader.js:1153:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10)
    at Module.load (internal/modules/cjs/loader.js:1000:32)
    at Function.Module._load (internal/modules/cjs/loader.js:899:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
    at internal/main/run_main_module.js:18:47