【发布时间】:2017-09-11 19:40:15
【问题描述】:
我不知道如何在我的 angular2 组件中要求节点模块 - 尤其是在我的情况下,如何在 angular2 组件中打开一个新的电子窗口。
我的 component.html 有这样的东西
<button class="btn btn-success" (click)="buttonLoginClick()">Login</button>
在 component.ts 中我使用以下内容
export class LoginComponent {
constructor() {}
buttonLoginClick(): void {
alert("just a test");
const remote = require('electron').remote;
const BrowserWindow = remote.BrowserWindow;
var win = new BrowserWindow({ width: 800, height: 600 });
win.loadURL('./test.html');
}
}
编译时的错误是说
找不到名称'require'。
【问题讨论】:
-
我认为你可以使用 import 而不是 require 你试过了吗?
-
试过了。没有编译错误,但在运行时我收到错误“fs.existsSync 不是函数”,并且在堆栈跟踪中它引用了 webpack_require。而不是普通的节点需要。此处描述了新错误github.com/electron/electron/issues/7300,但使用 window.require 的解决方案对我不起作用,因为现在使用 import 而不是 require
标签: node.js angular typescript electron require