首页 > 解决方案 > Angular 应用程序在电子中打开,但不在浏览器中

问题描述

在我声明的 main.js 文件中:

webPreferences: {
  nodeIntegration: true
}

所以,我可以在电子中打开应用程序,但在浏览器中我有一个错误:

TypeError: window.require is not a function

在我的组件中,我遇到了 require electron 错误,现在我使用:

declare var window: Window;
declare global {
  interface Window {
    process: any;
    require: any;
  }
}
const electron = window.require('electron');

我尝试了很多方法,但是浏览器无法识别window.require函数。

标签: angulartypescriptelectronnode-modulesrequire

解决方案


推荐阅读