Electron JS - 无法解构'require(...).remote'的属性'Brows

Electron JS - Cannot destructure property #39;BrowserWindow#39; of #39;require(...).remote#39; as it is undefined(Electron JS - 无法解构require(...).remote的属性BrowserWindow,因为它未定义)
本文介绍了Electron JS - 无法解构'require(...).remote'的属性'BrowserWindow',因为它未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

这是在渲染进程中:


const {BrowserWindow} = require('electron').remote

const path = require('path')
const url = require('url')

const newWindowButton = document.getElementById('new-window-btn');
newWindowButton.addEventListener('click',(e)=>{
    let win3 = new BrowserWindow();
    win3.loadURL(url.format({
        pathname: path.join(__dirname,'index3.html'),
        protocol: "file",
        slashes: true
    }))

})

我无法在渲染器进程中打开新窗口,出现以下错误.

**未捕获的类型错误:无法按原样解构require(...).remote"的属性BrowserWindow"

**Uncaught TypeError: Cannot destructure property 'BrowserWindow' of 'require(...).remote' as it is

undefined.**
    at Object.<anonymous> (D:ElectronTutehelloWorldindex1.js:4)
    at Object.<anonymous> (D:ElectronTutehelloWorldindex1.js:21)
    at Module._compile (internal/modules/cjs/loader.js:1145)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js`enter code here`:1166)
    at Module.load (internal/modules/cjs/loader.js:981)
    at Module._load (internal/modules/cjs/loader.js:881)
    at Function.Module._load (electron/js2c/asar.js:769)
    at Module.require (internal/modules/cjs/loader.js:1023)
    at require (internal/modules/cjs/helpers.js:77)
    at index1.html:13

推荐答案

 mainWindow = new BrowserWindow({
    width: 1280,
    height: 960,
    webPreferences: {
      nodeIntegration: true,
      enableRemoteModule: true,
     },
  });

我相信您正在使用新版本的 Electron.从 v9 版本开始,我们不允许在渲染器上使用 remote,除非将 enableRemoteModule 设置为 true.

I believe you are using the new version of Electron. From v9 version, we are not allowed to use remote on the renderer unless set the enableRemoteModule as true.

另外,为了使用 require() 在渲染器上加载 node_moduels,我们还需要启用 nodeIntegration.需要的是节点 API 之一.

Plus in order to load node_moduels on renderer by using require(), we need to also enable the nodeIntegration as well. As require is one of node APIs.

https://github.com/electron/electron/issues/21408

这篇关于Electron JS - 无法解构'require(...).remote'的属性'BrowserWindow',因为它未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Google apps script get range of bytes from binary file(谷歌应用程序脚本从二进制文件中获取字节范围)
Sending Multiple attachments with Google Script from Google Drive(使用 Google 脚本从 Google Drive 发送多个附件)
Distributing Google Apps Scripts for Sheets in your company network(在您的公司网络中分发适用于表格的 Google Apps 脚本)
Upload file to my google drive from anyone using javascript(使用 javascript 将文件从任何人上传到我的谷歌驱动器)
quot;Shared Drivequot; support in Google Apps Script(“共享驱动器Google Apps 脚本中的支持)
Angular 2+ HTTP POST and GDrive API. Resumable file upload with name(Angular 2+ HTTP POST 和 GDrive API.带名称的可恢复文件上传)